2

I am not sure about this, but does setting a core data object to nil, deletes it from Core Data. For Example:

MyObject *obj = [MyObject fetchFromCoreDataWithID:objectID];
obj = nil;

Does this deletes that object from Core Data ?

Soni
  • 454
  • 8
  • 23

4 Answers4

2

No. The object is only a representation of what is in your CoreData store. If you want to delete the object you must do this:

NSError *saveError = nil;
[_managedObjectContext deleteObject:obj];
[_managedObjectContext save:&saveError];
Eimantas
  • 48,927
  • 17
  • 132
  • 168
1

No.

You need to do the following to delete it:

[managedObjectContext deleteObject:obj]

See the documentation for more detail.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
1

No. To delete check out deleteObject.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62
0

You can also create your NSManagedObject without adding it to NSManagedObjectContext. Then you don't need to delete it at all. See this for more details: Inserting a new managed object in Core Data.

Community
  • 1
  • 1
Adam
  • 26,549
  • 8
  • 62
  • 79