gpt4 book ai didi

ios - stringByAppendingPathComponent 不可用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:09 30 4
gpt4 key购买 nike

我正在为 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 中,他们甚至更多地禁用了隐式转换

关于ios - stringByAppendingPathComponent 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32368708/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com