Objective-C: fetchManagedObjectsForEntity problem

Posted by Meko on Stack Overflow See other posts from Stack Overflow or by Meko
Published on 2010-04-11T23:43:40Z Indexed on 2010/04/11 23:53 UTC
Read the original article Hit count: 411

Filed under:
|
|

Hi.I am trying to get value from CoreData entity name Person with predicate and then comparing with new data in dictionary.But it it returns every time 0 .And it creates about 5 person with same name.

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userName == %@",[flickr usernameForUserID:@"owner"]];
    peopleList =  (NSMutableArray *)[flickr fetchManagedObjectsForEntity:@"Person" withPredicate:predicate];

        NSEnumerator *enumerator = [peopleList objectEnumerator];

        Person *person;

        BOOL exists = FALSE;

        while (person = [enumerator nextObject]) {
            NSLog(@" Person is: %@ ", person.userName);
            NSLog(@"Person ID IS %@",person.userID);
            NSLog(@"Dict ID is %@",[dict objectForKey:@"owner"]);
            if([person.userID  isEqualToString:[dict objectForKey:@"owner"]]) {
                exists = TRUE;
                NSLog(@"-- Person Exists : %@--", person.userName);
                [newPhoto setPerson:person];
            }

        }

Here peopleList returns 0 and the enumerator also 0 and it does not use if and not comparing.In my entity I have Person and Photo entities.In Person I have userName and userID attributes and also one-to many relationship with Photo entity.

I think problem in predicate but i cant figure out it .

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about core-data