Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the NSDocumentDirectory unique for a given application?

Tags:

cocoa

iphone

I would like to save some user-specific data in my iPhone app. I was looking at the SQLite sample, and it is using something similar to this:

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:dbName];

What I would like to know is, is "writableDBPath" unique for my app? Is there a risk that my "dbName" will clash with another file of the same name used by another app?

like image 458
Martin Cote Avatar asked Feb 02 '26 17:02

Martin Cote


1 Answers

On the iPhone, they are unique because of the application sandboxing that's done. On a regular mac, however, the NSDocumentDirectory is only unique to a user and if you don't make the file somehow unique or creating an application-specific sub-directory, you could get a name clash, so just be careful of that if you ever go from iPhone to Mac.

like image 150
Jason Coco Avatar answered Feb 04 '26 07:02

Jason Coco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!