如何获取sm_owner用户对象使用StackMob作为后端 [英] How to get the sm_owner User object using StackMob as backend

查看:182
本文介绍了如何获取sm_owner用户对象使用StackMob作为后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I find out the User has a sm_owner field. But how do I get the user using sm_owner. My code is like this:

    [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) {

    }];

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

And the crash message is:reason: 'Unimplemented SQL generation for predicate (sm_owner LIKE user / "user/test")'

推荐答案

我是StackMob的平台Evangelist。

I'm the platform Evangelist for StackMob.

getLoggedInUserOnSuccess方法的结果通常包含主键username。所以下面的代码应该工作。

The result from the getLoggedInUserOnSuccess method normally contains primary key "username". So the following code should work.

[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。我会做以下。

Alternatively, if you rather grab the sm_owner from the NSDictionary result. I would do the following.

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

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

然后执行您的提取操作。

Then perform your fetch.

这篇关于如何获取sm_owner用户对象使用StackMob作为后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆