gpt4 book ai didi

swift - 无论如何,要使用解析将对象保存到另一个用户吗?

转载 作者:行者123 更新时间:2023-11-30 14:10:11 25 4
gpt4 key购买 nike

我正在尝试创建一个可以关注用户的应用程序,我可以将我尝试关注的用户的 userId 保存到用户类中的“following”键。但是,我无法将当前用户 ID 保存到被关注用户的“关注者”键中。我收到错误“用户无法保存,除非他们已通过登录或注册进行身份验证”

func followUser() {
//User to be followed's username
var userName = self.title!
let myUserId = PFUser.currentUser()?.objectId




var query = PFUser.query()
query?.whereKey("objectId", equalTo: myUserId!)
query?.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let users = objects {
for user in users {
//thisUserId = objectId of user being followed
user.addUniqueObject(self.thisUserId, forKey: "following")
user.saveInBackgroundWithBlock({ (success, error) -> Void in
if error != nil {
println(error)
} else {
println("You favorited \(self.title)")
var otherQuery = PFUser.query()
otherQuery?.whereKey("objectId", equalTo: self.thisUserId)
otherQuery?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let users = objects {
for object in users {
if let user = object as? PFUser {
user.addUniqueObject(myUserId!, forKey: "followers")
user.saveInBackgroundWithBlock({ (success, error) -> Void in
if error == nil {
println("You are following \(self.title)")

} else {
println(error)
}
})
}
}
}
})

}
})
}
}
}
}

最佳答案

解析网站似乎能够更好地处理这个问题。您的代码没有任何问题(尽管它嵌套得很痛苦并且可以使用一些功能抽象)

https://parse.com/questions/user-cannot-be-saved-unless-they-have-been-authenticated-via-login-or-signup

关于swift - 无论如何,要使用解析将对象保存到另一个用户吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31861427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com