Append NSString to NSURL?

Josh Kahane picture Josh Kahane · Mar 14, 2011 · Viewed 17.8k times · Source

I have an NSURL, a file path, and I want to add an NSString to the end of it (the file name) how can I do this? But after this is don't I want the entire thing to be an NSURL.

Thanks.

Answer

lyzkov picture lyzkov · Nov 4, 2011

I think it's good solution:

NSURL *bUrl = [aUrl URLByAppendingPathComponent:@"newString"];

In Swift you could do the following,

var bURL = aURL.URLByAppendingPathComponent( "newString" )

You can also state whether the URL is a directory,

var bURL = aURL.URLByAppendingPathComponent( "newString", isDirectory: true )