OGeek|极客世界-中国程序员成长平台

标题: ios - 无法更新解析用户详细信息 - Swift [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:25
标题: ios - 无法更新解析用户详细信息 - Swift

我在 AppDelegate.swift 上使用以下代码来检查用户是否已登录以更改默认 View Controller 。

 if let user = PFUser.currentUser()!["username"] {

        print("asldkeu \(user)")
        // Code to execute if user is logged in
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController")

        self.window?.rootViewController = viewController
        self.window?.makeKeyAndVisible()

    } else {
        // Default screen you set in info plist.
    }

哪个工作正常,但问题是我无法更新我的在线解析用户数据。每当我尝试更新 Heroku Parse 应用程序上的任何数据时,都会收到以下错误代码:

Error Domain=Parse Code=206 "cannot modify user Jpibm8rWyI" UserInfo={code=206, temporary=0, error=cannot modify user Jpibm8rWyI, NSLocalizedDescription=cannot modify user

我正在使用下面的代码来更新解析数据:

if let games = PFUser.currentUser()?["gamesWon"]! {
            print("asldkeu server: \(games as! Int)")

            gamesWon = (games as! Int) + 1
                print("asldkeu update: \(gamesWon)")
            }


            PFUser.currentUser()?["gamesWon"] = gamesWon

            do {
                try PFUser.currentUser()!.save()
            } catch {
                print("asldkeu \(error)")
            }}

如果我使用 PFUser.currentUser()!.saveInBackground() 我不会收到错误消息,但不会保存数据。

任何帮助如何解决这个问题?



Best Answer-推荐答案


您不是强制解包用户。

而不是 PFUser.currentUser()?["gamesWon"] = gamesWon

使用

PFUser.currentUser()!["gamesWon"] = gamesWon

注意这里有一个 ! 而不是 ?

关于ios - 无法更新解析用户详细信息 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39278189/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4