Skip to content

Instantly share code, notes, and snippets.

@azizdev
Created February 5, 2016 14:04
Show Gist options
  • Save azizdev/5efe9620361cf11f7503 to your computer and use it in GitHub Desktop.
Save azizdev/5efe9620361cf11f7503 to your computer and use it in GitHub Desktop.
func getDirToImage(name : String) -> String {
let appDir = NSTemporaryDirectory()
let fullPath = String("\(appDir)\(name).jpeg")
return fullPath
}
func saveImage(image : UIImage, name: String){
let data = UIImageJPEGRepresentation(image, 1.0);
let fileManager : NSFileManager = NSFileManager.defaultManager()
// let appDir = NSSearchPathForDirectoriesInDomains(.LibraryDirectory,.UserDomainMask, true)
// let fullPath = String("\(appDir.first)/\(name).jpeg")
let appDir = NSTemporaryDirectory()
let fullPath = String("\(appDir)\(name).jpeg")
print("fullPath \(fullPath)")
fileManager.createFileAtPath(fullPath, contents: data, attributes: nil)
}
func loadImage(name: String) -> UIImage{
let appDir = NSTemporaryDirectory()
let fullPath = String("\(appDir)\(name).jpeg")
let img = UIImage(contentsOfFile: fullPath)
return img!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment