I'm updating my code for Swift 2, and I'm running into issues with my image file path that I have saved locally for a user profile. I'm not sure where to even fix this, I've tried with the URLByAppendPathComponent but I'm not sure what I'm missing
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()
}
If anyone can help me figure out how to update my code here, I would greatly appreciate it!
Thanks!
let nsPath = Path as! NSString
现在NSPath拥有你想要的所有功能 - 在swift2.0中它们有点禁用隐式转换
Hey I had the same problem.. and i changed .stringByAppendingPathComponent("profileImage.jpeg")
with .stringByAppendingString("/profileImage.jpeg")
..
The thing that's importen here is the forwardslash /
.
Replace this
var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
with
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.