Reputation: 920
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?
Upvotes: 0
Views: 660
Reputation: 3360
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.
Upvotes: 3