1
votes

I have a pretty weird problem. I'm using coredata to save notes. I can access/save/edit all the attributes of the "Notes" entity, besides one : category.

-(void)editCategory {

    NSFetchRequest *request = [[NSFetchRequest alloc]init];
    NSEntityDescription *categRequest = [NSEntityDescription entityForName:@"Notes" inManagedObjectContext:_managedObjectContext];
    request.predicate = [NSPredicate predicateWithFormat:@"text = %@", noteToEdit];
    [request setEntity:categRequest];

    //Error handling
    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error]mutableCopy];
    if (mutableFetchResults == nil) {
        NSLog(@"Error happened : %@", error);
    }

    Notes *editMe = [mutableFetchResults objectAtIndex:0];
    [editMe setCategory:editCategoryText];
    NSLog(@"Category from pickerview : %@", editCategoryText);
    if (![_managedObjectContext save:&error]) {
        NSLog(@"couldnt save : %@", error);
    }
}

This line :

[editMe setCategory:editCategoryText];

is crashing. editCategoryText is a string, as the category attribute. The weird thing is that I'm using the exact same piece of code to change the title attribute, and I don't have any problem.

Log file :

2013-11-07 15:49:20.286 Simple Notes 1[16511:a0b] -[__NSCFString managedObjectContext]: unrecognized selector sent to instance 0x8dccc30
2013-11-07 15:49:20.293 Simple Notes 1[16511:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString managedObjectContext]: unrecognized selector sent to instance 0x8dccc30'

Do you have any idea why this attribute is behaving differently from the others ? Thank you.

2
Try using NSArray for the results rather than a mutableArray. - Duncan Groenewald

2 Answers

0
votes

Not at a computer so can't test this but:

Get rid of the mutableCopy. executeFetchRequest returns autoreleased objects, which you are then trying to copy, this turns into a garbage pointer, which happens to end up pointing to a string.

0
votes

Actually it seems like it was a core data bug, I solved it by deleting my app in the simulator, deleting the core data model in xcode, built it again and performed a clean.