ios - 无法更新解析用户详细信息 - Swift
<p><p>我在 AppDelegate.swift 上使用以下代码来检查用户是否已登录以更改默认 ViewController 。</p>
<pre><code> 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.
}
</code></pre>
<p>哪个工作正常,但问题是我无法更新我的在线解析用户数据。每当我尝试更新 Heroku Parse 应用程序上的任何数据时,都会收到以下错误代码:</p>
<blockquote>
<p>Error Domain=Parse Code=206 "cannot modify user Jpibm8rWyI" 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()?["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)")
}}
</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()!["gamesWon"] = 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]