swift Swift-将图像保存在文档目录中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift Swift-将图像保存在文档目录中相关的知识,希望对你有一定的参考价值。
See: https://www.appcoda.com/cloudkit-introduction-tutorial/
01. Declare:
var imageURL: NSURL!
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
let tempImageName = "temp_image.jpg"
02. Create a custom method
func saveImageLocally() {
let imageData: NSData = UIImageJPEGRepresentation(imageView.image, 0.8)
let path = documentsDirectoryPath.stringByAppendingPathComponent(tempImageName)
imageURL = NSURL(fileURLWithPath: path)
imageData.writeToURL(imageURL, atomically: true)
}
03. Call it
saveImageLocally()
以上是关于swift Swift-将图像保存在文档目录中的主要内容,如果未能解决你的问题,请参考以下文章