上下文类型"AnyObject"不能与数组文字一起使用

Man*_*our 11 parse-platform swift

我正在尝试升级以将我的项目升级到Swift 2,但我坚持以下错误:

上下文类型"AnyObject"不能与数组文字一起使用

这是我的代码:

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {

    let data = UIImageJPEGRepresentation(image, 0.08)
    let file = PFFile(data: data!)

    PFUser.currentUser()!["Picture"] = [file]
    try! PFUser.currentUser()!.save()}
Run Code Online (Sandbox Code Playgroud)

这是问题发生的地方

        PFUser.currentUser()!["Picture"] = [file]
Run Code Online (Sandbox Code Playgroud)

非常感谢你的帮助 !!(我是初学者,......)

Uni*_*kat 5

替换这一行:

PFUser.currentUser()!["Picture"] = [file]
Run Code Online (Sandbox Code Playgroud)

有:

PFUser.currentUser()!["Picture"] = file
Run Code Online (Sandbox Code Playgroud)

编辑:如上所述,最好不要强制解包条件并执行以下操作:

guard let user = PFUser.currentUser() else {
    return
}
user["Picture"] = file
Run Code Online (Sandbox Code Playgroud)