gpt4 book ai didi

ios - 将字符串转换为 PFObject.. 解析

转载 作者:行者123 更新时间:2023-11-29 01:47:29 24 4
gpt4 key购买 nike

我正在以这种方式检索所有用户详细信息..

var userIds = [String]()
var userNames = [String]()
var profilePics = [PFFile]()
var gender = [String]()


override func viewDidLoad() {
super.viewDidLoad()

var userQuery = PFUser.query()
userQuery?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

if let objects = objects {

self.userIds.removeAll(keepCapacity: true)
self.userNames.removeAll(keepCapacity: true)
self.profilePics.removeAll(keepCapacity: true)

for object in objects {

if let user = object as? PFUser {
if user.objectId != PFUser.currentUser()?.objectId {

self.userIds.append(object.objectId as String!)
self.userNames.append(object["fullName"] as! String!)
self.profilePics.append(object["profilePicture"] as! PFFile!)
self.gender.append(object["gender"] as! String!)

}


}

}


}


self.tableView.reloadData()

})

}

现在我在 myCell 中有“关注”按钮.. 以这种方式保存..

 @IBAction func followButtonTapped(sender: UIButton) {

var followers:PFObject = PFObject(className: "Followers")
followers["user"] = userIds[sender.tag] // Problem is here.. i want "user" column to be filled with userIds of users as Pointers not Strings. What should i do here??
followers["follower"] = PFUser.currentUser()

followers.saveInBackground()

}

因为我想与“Followers”类中的每个对象建立关系,这就是为什么我希望它们采用指针的形式。有什么建议吗??

最佳答案

如果您想创建指向另一个 PFObject(包括 PFUser)的指针,您将需要实际指向该对象。

我在您的查询中看到您没有将任何 PFUsers 添加到数组中,但您正在获取它们的对象 ID。

由于标签仅适用于 Int,因此您不能使用它来传递 String(Parse objectID 就是)。

您可以子类化 UIButton 并创建一个新属性来处理来自 parse 的 objectID,然后使用它来对 objectID 执行查询并保存指向该查询结果的指针。或者,您可以将第一个查询中的对象添加到本地数组,并使用按钮的标签获取您要指向的对象的索引。

更新

由于您拥有所需 PFuser 的 objectId,因此您可以获取它并更新您的关注者,如下所示:

        let getOjbectByIdQuery = PFQuery(className: "User")
getOjbectByIdQuery.whereKey("objectId", equalTo: userIds[sender.tag])
getOjbectByIdQuery.getFirstObjectInBackgroundWithBlock { (foundObject: PFObject?, error: NSError?) -> Void in

if let object = foundObject {

var followers:PFObject = PFObject(className: "Followers")
followers["user"] = object
followers["follower"] = PFUser.currentUser()
follwers.saveInBackground()

}
}

关于ios - 将字符串转换为 PFObject.. 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735055/

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