Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Managed Object to Data object

Tags:

ios

core-data

How do I convert my NSManagedObject to NSData object?

I'm new to Core Data and the Multipeer Connectivity Framework.

I need to transfer data between 2 devices via the Multipeer Connectivity Framework. I understand that I cannot simply transfer via MPC since it requires an NSData object.

Are there any third-party libraries that provides such function?

like image 442
Scott Avatar asked Sep 28 '26 22:09

Scott


1 Answers

I think NSCoding is not such a good idea here. The reason is that the objects will not be the same on two different devices due to their internal managed object IDs as well as a myriad of other possible problems that can occur in unexpected syncing scenarios.

I would strongly recommend to take the trouble and convert your object into a NSDictionary type and then use the standard NSData APIs on the dictionary (or an array of dictionaries).

like image 189
Mundi Avatar answered Oct 01 '26 15:10

Mundi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!