Question

Until now, I've been using the following to initialize my NSPersistentStoreCoordinator's db path:

[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) lastObject];

However, Xcode now auto-populates my app delegate with a method

(NSURL *)applicationDocumentsDirectory:

which returns:

[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

Are there benefits or drawbacks to either one or are they just two ways of doing the exact same thing?

Was it helpful?

Solution

Using NSFileManager is the preferred way as written in the Docs: Foundation Functions Reference (NSSearchPathForDirectoriesInDomains)

You should consider using the NSFileManager methods URLsForDirectory:inDomains: and URLForDirectory:inDomain:appropriateForURL:create:error:. which return URLs, which are the preferred format.

I don't know if there are any real drawbacks when using NSSearchPathForDirectoriesInDomains to determine the URL to your documents directory. I would recommend to use NSFileManager and it's method as this is the quasi-convenient way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top