我正在更新Swift 2的代码,而我在本地为用户配置文件保存的图像文件路径遇到了问题。我不确定在哪里解决此问题,我尝试过使用URLByAppendPathComponent,但不确定是否丢失了什么
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
profileImageView.image = image
let fileManager = NSFileManager.defaultManager()
var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
var filePathToWrite = "\(paths)/profileImage.jpeg"
var imageData : NSData = UIImageJPEGRepresentation(image, 1.0)!
fileManager.createFileAtPath(filePathToWrite, contents: imageData, attributes: nil)
let imageFile : PFFile = PFFile(name: "profileImage.jpeg", data: imageData)
imageFile.save()
let getImagePath = paths.stringByAppendingPathComponent("profileImage.jpeg")
print("getImagepath: \(getImagePath)")
let user = PFUser.currentUser()
user.setObject(imageFile, forKey: "profileImage")
user.saveEventually()
}
如果有人可以帮助我找出如何在此处更新代码,我将不胜感激!
谢谢!
let nsPath = Path as! NSString
现在,NSPath具备了您想要的所有功能-在swift2.0中,它们还禁用了隐式强制转换
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句