An object that parses URLs into and constructs URLs from their constituent parts.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
NSURLComponents class is a class that is designed to parse URLs based on RFC 3986 and to construct URLs from their constituent parts. Its behavior differs subtly from the
NSURL class, which conforms to older RFCs. However, you can easily obtain an
NSURL object based on the contents of a URL components object or vice versa.
You create a URL components object in one of three ways: from an
NSString object that contains a URL, from an
NSURL object, or from scratch by using the default initializer. From there, you can modify the URL’s individual components and subcomponents by modifying various properties, either in unencoded form or in URL-encoded form. If you set the unencoded property, you can then obtain the encoded equivalent by reading the encoded property value and vice versa.