[英]Cannot update parse user details - Swift
I use below code on AppDelegate.swift to check if a user is logged in in order to change the default view controller. 我在AppDelegate.swift上使用以下代码来检查是否已登录用户以更改默认视图控制器。
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.
}
Which works correctly, but the problem is that then I cannot update my online parse user data. 哪个可以正常运行,但是问题是我无法更新我的在线解析用户数据。 Whenever I try to update any data on my Heroku Parse app I get below error code: 每当我尝试更新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 错误域=解析代码= 206“无法修改用户Jpibm8rWyI” UserInfo = {代码= 206,临时= 0,错误=无法修改用户Jpibm8rWyI,NSLocalizedDescription =无法修改用户
I am using below code to update parse data: 我正在使用下面的代码更新解析数据:
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)")
}}
And if I use PFUser.currentUser()!.saveInBackground() I don't get an error, but the data isn't saved. 而且,如果我使用PFUser.currentUser()!. saveInBackground(),则不会收到错误消息,但不会保存数据。
Any help how this can be solved? 任何帮助如何解决?
You are not force unwrapping the user. 您并没有强制解包用户。
instead of PFUser.currentUser()?["gamesWon"] = gamesWon
而不是PFUser.currentUser()?["gamesWon"] = gamesWon
use 采用
PFUser.currentUser()!["gamesWon"] = gamesWon
Note that there is a !
注意这里有一个!
rather than ?
而不是?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.