gpt4 book ai didi

swift - 如何访问 Parse 的用户 (PFUser) 对象的剩余字段?

转载 作者:行者123 更新时间:2023-11-28 07:07:31 25 4
gpt4 key购买 nike

我正在尝试访问当前用户的数据字段余额。
以下是我在调试器中查询 currentUser 时只能看到的内容:

(lldb) po currentUser
<PFUser: 0x17642d80, objectId: FUsro30ZFu, localId: (null)> {
displayName = Turkey;
email = "frederick.c.lee@gmail.com";
firstName = Frederick;
lastName = Lee;
username = "UncleRic ";
}

这是我想要获得的领域(与其他领域一样): enter image description here

这些是不成功的尝试:

(lldb) po currentUser["location"]
error: indexing expression is invalid because subscript type 'const char *' is not an Objective-C pointer
error: 1 errors parsing expression
(lldb) po currentUser.location
error: property 'location' not found on object of type 'PFUser *'
error: 1 errors parsing expression
(lldb) po currentUser.valueForKey("location")
error: property 'valueForKey' not found on object of type 'PFUser *'
error: 1 errors parsing expression

访问对象“PFUser”的剩余字段的正确方法是什么?


另外,如何更新/分配 PFUser 的字段值?
显然我需要将 String 重铸为 AnyObject 对象。但是“位置”字段已经被定义为一个字符串字段。

enter image description here

最佳答案

这里有几个问题。

1) 我试图在调试器中使用 Swift 而不是 Objective-C。
所以我把语法搞砸了。

2) 在我在线(通过网络)更改我的 parse.com 数据后,我没有重新启动(冷启动)我的应用程序@设备。所以我在寻找潜在的(非刷新数据)。

以下是查看 PFUser 属性值的正确格式:

(lldb) po [currentUser objectForKey:@"firstName"]
Frederick

(lldb) po [currentUser objectForKey:@"location"]
Ann Arbor

下面是更新 PFUser 对象的正确 Swift 语法。 注意:确保在后端线程上完成实际的 SAVE()。

代码用户本质上是我可以实际更新文件的概念验证。

func updateParseUser(newUser:User, sender:UIViewController) {

let currentUser = PFUser.currentUser()

if ((currentUser) == nil) {
return
}

if let revisedlocation = newUser.location {
currentUser?.setValue(revisedlocation, forKey: "location")
}

if let phone = newUser.phoneNumber {
currentUser?.setValue(phone, forKey: "phone")
}

currentUser!.save()

}

感谢反馈

关于swift - 如何访问 Parse 的用户 (PFUser) 对象的剩余字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29882591/

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