gpt4 book ai didi

ios - 如何使 Parse Installation 对象的属性成为指向 User 对象的指针?

转载 作者:行者123 更新时间:2023-11-29 02:42:57 25 4
gpt4 key购买 nike

目前,当用户第一次打开我的 Parse 应用程序时,会在 Parse 数据库上创建一个新的 Installation 对象及其 installationId 和其他属性。

一旦他们登录,它就会更新此Installation 对象的userId 属性为该人的UserobjectId 字符串> 对象。它只不过是一个恰好等同于相应 User objectId 的字符串,但我想要的是它也是指向该 User 对象的指针。

我已经尝试将 userId 属性设置为一个指针而不是来自网站的字符串,但这给了我一个来自应用程序的错误,指出 Error: invalid type for key userId ,预期的对象,但得到了字符串,因为我的 iOS 代码将它作为字符串发送,而不是作为指向 User 类的指针。

如何使 userId 字符串指向代码中的 User 类?文档是 here ,但我无法将其应用于此用例。

代码:

- (void)viewWillAppear:(BOOL)animated {
[super viewDidLoad];
if ([PFUser currentUser]) {
NSLog(@"User is logged in");

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
NSString *userId = [PFUser currentUser].objectId;

//userId[@"parent"] = [PFUser currentUser];

[currentInstallation setObject:userId forKey: @"userId"];
[currentInstallation saveInBackground];

} else {
NSLog(@"User is not logged in");
//[welcomeLabel setText:@"Not logged in"];
}
}

最佳答案

在解析中将一个点存储到一个对象的方法是将整个对象保存到它。所以不要将 userId 存储在 NSString 中。只需执行以下操作:

- (void)viewWillAppear:(BOOL)animated {
[super viewDidLoad];
if ([PFUser currentUser]) {
NSLog(@"User is logged in");

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
PFUser* user = [PFUser currentUser];

[currentInstallation setObject:user forKey: @"userId"];
[currentInstallation saveInBackground];

} else {
NSLog(@"User is not logged in");
//[welcomeLabel setText:@"Not logged in"];
}
}

这将导致 parse 根据需要保存指向用户的指针。

关于ios - 如何使 Parse Installation 对象的属性成为指向 User 对象的指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25531645/

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