Tom
Tom

Reputation: 3627

Xcode and iOS app data file placements defaults

Is my understanding correct for iOS7-iOS9:

1) "built-in" app cache path is NSHomeDirectory() + "/Library/Caches/"

2) app launch images and icons are placed NSBundle.mainBundle().resourcePath! (where does this map down to?)

3) a "blue" folder I have added in "xcode - build phases - copy bundle resources called "ownassets"" is placed in...? NSHomeDirectory() + "/Library/"

I am just tying to make 100% sure if I understood correctly where files are placed, so I can read and load them during app execution (and write in my cache)

Note: I realize that release code should use system calls to get paths since Apple may changes paths in future iOS versions.

Note For hose looking on how to get normal IO file read access to folders and content you added in "Build phases > Copy Bundle Resources" this is how: NSBundle.mainBundle().resourcePath! + "/" + nameoffolder

Upvotes: 0

Views: 139

Answers (1)

jtbandes
jtbandes

Reputation: 118681

You should not think much about the actual locations on disk, but use the higher-level system APIs to find files/paths:

  1. Caches directory:

    let cacheURL = try NSFileManager.defaultManager().URLForDirectory(.CachesDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
    
  2. App resources in the bundle:

    • let image = UIImage(named: "imageName")
    • let path = NSBundle.mainBundle().pathForResource("image", ofType: "png")
  3. App resources in subdirectories:

    let path = NSBundle.mainBundle().pathForResource("info", ofType: "dat", inDirectory: "AdditionalResources")
    

For more info, see the File System Programming Guide.

Upvotes: 3

Related Questions