Search code examples
swiftios8xcode6dir

swift path to custom dir for images


I have imagesDir in myproject dir

MyProject
---- MyProject
     ---- AppDelegate.swift
     ---- Main.storyboard
     ---- ImagesDir
          ---- images1.jpg
          ---- images2.jpg

How can retrive the correct path to "imagesDir"

Is a good idea to save in "imagesDir" the images saved by my application?

Thanks!!!


Solution

  • In iOS, you can't write data into NSBundle. Instead, write into document directory.

    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0] as String
    // documentsDirectory is your app's document path