How to get URL for application's document directory iPhone

前端 未结 4 1181
迷失自我
迷失自我 2020-12-05 04:09

This code is a part of Core Data. The URLsForDirectory....method does not run on iOS < 4 so I need to know some other methods/objects to call. I would also appriciate doc

4条回答
  •  余生分开走
    2020-12-05 04:36

    An alternative solution would be to use the -[NSFileManager URLsForDirectory:inDomains:] method and fetching the path from the returned NSArray:

    Objective-C:

    NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
    NSURL *documentsURL = [paths lastObject];
    

    Swift:

    let paths = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    let documentsURL = paths[0] as! NSURL
    

    This is supported in iOS 4.0+

提交回复
热议问题