Save UIImage as File

Steps

  • Get NSData using UIImagePNGRepresentation
  • Write NSData into file

Sample

image is UIImage

var data = UIImagePNGRepresentation(image)
var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask, true)
var docpath : AnyObject = path[0]
let filePath = docpath.stringByAppendingPathComponent("sample.png");
data.writeToFile(filePath, atomically:true)