views:

73

answers:

1

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 .

A: 

Hi I fixed my problem ,in my etchManagedObjectsForEntity declaration I used user instead of userName .))

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
Meko