Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I join path fragments using objective-C in iOS?

What's the objective-C equivalent of python's os.path.join in iOS? e.g.:

>>> import os
>>> os.path.join("foo", "bar", "buuxometer", "hi.jpg")
'foo/bar/buuxometer/hi.jpg'
like image 268
Claudiu Avatar asked Sep 12 '13 23:09

Claudiu


1 Answers

You are looking for [NSString pathWithComponents] which, per the link will:

Returns a string built from the strings in a given array by concatenating them with a path separator between each pair.

In your sample:

NSArray *components = [NSArray arrayWithObjects:@"foo", @"bar", @"buuxometer", @"hi.jpg", nil];
NSString *path = [NSString pathWithComponents:components];
like image 163
DocMax Avatar answered Sep 18 '22 14:09

DocMax