4
votes

core data getting on my nerves. i' m deleting old data and want to insert new data received from server.

now the deleting part gives a "sigabort":

-[NSManagedObjectContext delete:]: unrecognized selector sent to instance 0x522f550 2013-09-27 14:05:56.592 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObjectContext delete:]: unrecognized selector sent to instance 0x522f550' * First throw call stack: (0x320f82a3 0x39d4797f 0x320fbe07 0x320fa531 0x32051f68 0x1b6c53 0x1868e5 0x3a15f11f 0x3a16d259 0x3a16d3b9 0x3a193a11 0x3a1938a4) libc++abi.dylib: terminate called throwing an exception

deleting happens in background and nsmanagedobjectcontext is a privet concurrency type i printed the pointer for context and object context

po context NSManagedObjectContext: 0x522f550

and

po tmpCon.managedObjectContext NSManagedObjectContext: 0x522f550>

and the code for deleting is:

     NSError *errorAllCons = nil;
    NSFetchRequest *allevents = [[NSFetchRequest alloc] init];
    [allevents setEntity:[NSEntityDescription entityForName:@"TEventContact" inManagedObjectContext:context]];
    NSArray *allCons = [context executeFetchRequest:allevents error:&errorAllCons];
    for (TEventContact *tmpCon in allCons)
    {
        [context delete:tmpCon];
    }

and it crashes on [context delete:tmpCon]; can someone let me know what am i doing wrong?

2
NSManagedObjectContext does not have a delete: method, maybe deleteObject:pNre

2 Answers

24
votes

Use

 [context deleteObject:tmpCon];

It will solve the problem

2
votes

do it like this for deleting an object permanently

for (TEventContact *tmpCon in allCons)
{
    [context deleteObject:tmpCon] /// for deleting object in context
}    
[context save]; /// to reflect changes in database you need to save that context

without saving the context it doesn't reflect on data base and that may cause DIRTY_READ for another context