gpt4 book ai didi

iphone - 如何使用 StackMob 作为后端获取 sm_owner 用户对象

转载 作者:行者123 更新时间:2023-11-29 04:09:22 26 4
gpt4 key购买 nike

我发现用户有一个 sm_owner 字段。但是我如何让用户使用 sm_owner.我的代码是这样的:

    [self.client getLoggedInUserOnSuccess:^(NSDictionary *result) {
NSString *currentLogginedUser = [result valueForKey:@"sm_owner"];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedOjbectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"sm_owner like user/%@", currentLogginedUser];
[request setPredicate:predicate];
self.user = [[self.managedOjbectContext executeFetchRequest:request error:nil] objectAtIndex:0];
} onFailure:^(NSError *error) {

}];

崩溃消息是:原因:'未实现谓词的 SQL 生成(sm_owner LIKE user/“user/test”)'

最佳答案

我是 StackMob 的平台布道者。

getLoggedInUserOnSuccess 方法的结果通常包含主键“用户名”。所以下面的代码应该可以工作。

[self.client  getLoggedInUserOnSuccess:^(NSDictionary *result) {                
NSString *currentLogginedUser = [result objectForKey:@"username"];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedOjbectContext];
[request setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"username == %@", currentLogginedUser];
[request setPredicate:predicate];
self.user = [[self.managedOjbectContext executeFetchRequest:request error:nil] objectAtIndex:0];
} onFailure:^(NSError *error) {

}];

或者,如果您愿意从 NSDictionary 结果中获取 sm_owner。我会做以下事情。

NSString *sm_owner = [result valueForKey:@"sm_owner"];

NSArray *myArray = [sm_owner componentsSeparatedByString:@"/"];
NSString *currentLogginedUser = [myArray objectAtIndex:1];

然后执行提取。

关于iphone - 如何使用 StackMob 作为后端获取 sm_owner 用户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663490/

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