0

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

    }];

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

yong ho
  • 3,892
  • 9
  • 40
  • 81

1 Answers1

1

I'm the platform Evangelist for StackMob.

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

}];                

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.

Sidney Maestre
  • 383
  • 1
  • 5