Structure
URI
struct URI
Overview
Warning
This is NOT the same as Foundation’s URL type!
Can be used to both parse strings containing well-formed URIs and to generate such strings from a set of individual URI components.
Use of this type is (gently, for now) discouraged. Consider using Foundation’s URL and/or URLComponents types instead. See below for details.
URI is for URLs, not URIs
Thanks to both backwards compatibility requirements and name collision concerns, this type, despite its name, does not actually represent a generic Uniform Resource Identifier as defined by RFC 3986. In particular, the underlying implementation is currently based on Foundation’s URLComponents type, whose semantics are inconsistent between different methods; in addition, its behavior has differed drastically between the macOS and Linux implementations for most of its existence, and continues to do so in Swift 5.9. This is not expected to be remedied until the swift-foundation package reaches a 1.0 release, which as of this writing will not for quite some time yet). In short, instances of URI may not always behave as expected according to either the spec or what Foundation does.
Topics
Structures
struct SchemeA URI scheme, as defined by RFC 3986 § 3.1 and [RFC 7595].
Initializers
init(from: any Decoder) throwsinit(scheme:host:port:path:query:fragment:)init(scheme:userinfo:host:port:path:query:fragment:)Construct aURIfrom various subcomponents.init(string: String)init(stringLiteral: String)
Instance Properties
var description: Stringvar fragment: String?var host: String?var path: Stringvar port: Int?var query: String?var scheme: String?var string: Stringvar userinfo: String?
Instance Methods
Relationships
Conforms To
Swift.CustomStringConvertibleSwift.DecodableSwift.EncodableSwift.EquatableSwift.ExpressibleByExtendedGraphemeClusterLiteralSwift.ExpressibleByStringInterpolationSwift.ExpressibleByStringLiteralSwift.ExpressibleByUnicodeScalarLiteralSwift.HashableSwift.SendableSwift.SendableMetatype