Objective-c – Append NSString to NSURL

appendmacosnsstringnsurlobjective c

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.

Best Answer

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 )