Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Removing an attributes value from core data

Hi! I want to know how to remove a specific attribute from a coreDataStack. for example if i have an attribute in my coreDataStack (the entity is called: entityExample) that is called photoData.

I want to allow the user to click a delete button on the image (a small cross overlay) and it removes the imageData attribute's value from the coreDataStack.

here is my code within the buttonPressed method;

[[coreDataStack managedObjectContext]deleteObject:_entityExample.photoData];
[coreDataStack saveContext];

however, i get an error of incompatible pointer types as 'deleteObject:_entityExample.imageData];' is should have a managedObjectContext value not a NSData value.

Any help is much appreciated

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The deleteObject method deletes a managed object from the context and not an attribute. If you want update/change the value of an attribute then simply assign it a value and then save the context.

_entityExample.photoData = nil;
[coreDataStack saveContext];