How would I go about using bluetooth to transfer a core data entity with it’s corresponding relationships? I have three core data entities with inverse relationships set up and it all works fine, but I need to transfer these to another iPhone based on the context that it is not in the corresponding table in the core data entity set on the other iPhone. I know how to transfer simple things such as strings and integers over bluetooth, but this is on a whole new level, and I only started programming for iPhone around 4 month ago. Thanks for all your help you experts!
EDIT:
Thanks, but for some reason I keep getting this error! What should I do?
2010-02-12 21:24:14.907 PitScout[92918:207] Failed to call designated initializer on NSManagedObject class 'Team'
2010-02-12 21:24:14.907 PitScout[92918:207] *** -[Team setTeamNumber:]: unrecognized selector sent to instance 0x112b630
2010-02-12 21:24:14.908 PitScout[92918:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Team setTeamNumber:]: unrecognized selector sent to instance 0x112b630'
Thanks.
You will need to serialize your objects in some way to transfer and then re-insert into a context on the other side. I suggest looking into the
NSCodingprotocol and examples which will allow you to useNSKeyedArchiverandNSKeyedUnarchiverto serialize your objects toNSDatafor transfer (or base64 encoded to anNSStringif necessary).First make sure your model object implements NSCoding:
And then implement the following methods in your model object to handle the encoding and decoding of the objects:
Use
NSKeyedArchiverto serialize your object toNSData:Use NSKeyedUnarchiver to deserialize:
If a string is required then you’ll have to base64 encode and decode the
NSData, see this post for details on that: How do I do base64 encoding on iphone-sdk?