Clicky

iOS Dev Nugget 65 NSURLComponents

.

Need to run a code review on your codebase? Hire me

In Apple's iOS 7 Tech Talks, the class NSURLComponents was mentioned. It's a very useful utility for manipulating URLs (examples taken and modified from Apple):

NSURLComponents* components = [[NSURLComponents alloc] init];
components.scheme = @"https";
components.user = @"pmarcos";
components.password = @"seecret";
components.host = @"example.com";
components.path = @"/site/doc.html";
components.fragment = @"section3";
NSURL* url = components.url;

and:

NSURLComponents* components = [NSURLComponents componentsWithString:@"https://pmarcos:seecret@example.com/site/doc.html#section3"];
components.password = @"changed";
NSURL* secretPigFaceURL = components.URL;
//https://pmarcos:changed@example.com/site/doc.html#section3

At the time of writing, there are no docs for NSURLComponents, so you'll have to refer to the NSURL.h header file.

Download the iOS 7 Tech Talks videos and slides.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues