菜鸟教程小白 发表于 2022-12-11 17:25:38

ios - 无法更新解析用户详细信息 - Swift


                                            <p><p>我在 AppDelegate.swift 上使用以下代码来检查用户是否已登录以更改默认 ViewController 。</p>

<pre><code> if let user = PFUser.currentUser()![&#34;username&#34;] {

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

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

    } else {
      // Default screen you set in info plist.
    }
</code></pre>

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

<blockquote>
<p>Error Domain=Parse Code=206 &#34;cannot modify user Jpibm8rWyI&#34; UserInfo={code=206, temporary=0, error=cannot modify user Jpibm8rWyI, NSLocalizedDescription=cannot modify user</p>
</blockquote>

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

<pre><code>if let games = PFUser.currentUser()?[&#34;gamesWon&#34;]! {
            print(&#34;asldkeu server: \(games as! Int)&#34;)

            gamesWon = (games as! Int) + 1
                print(&#34;asldkeu update: \(gamesWon)&#34;)
            }


            PFUser.currentUser()?[&#34;gamesWon&#34;] = gamesWon

            do {
                try PFUser.currentUser()!.save()
            } catch {
                print(&#34;asldkeu \(error)&#34;)
            }}
</code></pre>

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

<p>任何帮助如何解决这个问题?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您不是强制解包用户。</p>

<p>而不是 <code>PFUser.currentUser()?["gamesWon"] = gamesWon
</code></p>

<p>使用</p>

<pre><code>PFUser.currentUser()![&#34;gamesWon&#34;] = gamesWon
</code></pre>

<p>注意这里有一个 <code>!</code> 而不是 <code>?</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 无法更新解析用户详细信息 - Swift,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39278189/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39278189/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 无法更新解析用户详细信息 - Swift