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
  • 464
  • 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,240
  • 16
  • 132
  • 164
1

No.

You need to do the following to delete it:

[managedObjectContext deleteObject:obj]

See the documentation for more detail.

Stephen Darlington
  • 50,715
  • 11
  • 102
  • 148
1

No. To delete check out deleteObject.

unexpectedvalue
  • 6,049
  • 3
  • 36
  • 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
  • 25,787
  • 8
  • 61
  • 77