I need to transfer a single object across device. Right now I am converting my NSManagedObject to a dictionary , archiving it and sending as NSData. Upon receiving I am unar
The problem is obviously the unarchiver. In the end there is no way to use both initWithEntity:
and initWithCoder:
in the same object. However, I suspect that with some trickery you may be able to make this work. For instance, implement initWithCoder:
as you have done, and in that create another managed object with initWithEntity:
(this means you will need unmanaged ivars that can hold such a reference. Implement forwardingTargetForSelector:
, and if the object is the one being created using initWithCoder:
, forward it to the shadow object you created with initWithEntity:
(otherwise, forward that selector to super). When the object is decoded fully, then ask it for the real managed object, and you're done.
NOTE: I have not done this but have had great success with forwardingTargetForSelector:
.