I have an object Recipein Core Data that can contain an object Photo. The latter contains a property NSDatafor the image and some useful properties.
I am having inconvenience when changing Photo Recipe:
recipe.photo = [Photo insertIntoContext: ctxt];
If recipe.photoit was nil, everything works as expected. However, if it had a previous instance Photo, it becomes “garbage”, with the nilrecipe property (photo feedback) and throws an exception when saving (the recipe is not optional in my model).
So I have to do something like this:
if(!recipe.photo){
[ctxt deleteObject:recipe.photo);
}
recipe.photo = [Photo insertIntoContext: ctxt];
It looks horrible, like manual memory management, where I have to make sure that the “lost” is Photodeleted.
. ?