Tuesday, October 15, 2013 [Tweets] [Favorites]

KSURLComponents

Mike Abdullah:

I daresay Apple faced this same decision. NSMutableURL initially makes the most sense as a companion to all the NSMutableFoo classes in Foundation. But closer inspection reveals the awkward problem that many mutations cannot result in a valid URL. For example, trying to specify a relative path is only allowed if there’s no scheme or authority component. That then leaves our theoretical NSMutableURL class with having to throw exceptions, throw away data, or exist in some unusual invalid state when such a mutation is requested. And don’t even get started on handling URL schemes that don’t conform to RFC 1808

Instead, NSURLComponents — along the same lines as NSDateComponents — probably makes the most sense. All mutations are legal, and -URL will simply return nil until a valid combination of components is specified.

NSURLComponents is great, but it’s not available on Mac OS X 10.8 or iOS 6, hence his clone.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment