我发现用户有一个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用户/“用户/测试”)'
答案 0 :(得分:1)
我是StackMob的平台传播者。
getLoggedInUserOnSuccess方法的结果通常包含主键“username”。所以下面的代码应该可以工作。
[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];
然后执行你的获取。