vondip
vondip

Reputation: 14039

coredata - save content as json string or nsdata

In my iOS app I've got a server sending me json messages. I decode those json messages and built a custom object from.

Amongst the json data I also get a property of custom objects which get decoded differently by different controllers, so I'd rather keep that information decoded / in raw format and not build a custom class from it.

I wish to save the object and its custom data to a local database using coredata. I'm now contemplating the two alternatives.

  1. Saving the custom data as raw NSString property of larger object
  2. Saving the custom data as NSData property of larger object

With which one should I go? What's the best practice here?

Upvotes: 0

Views: 198

Answers (1)

Wain
Wain

Reputation: 119031

Use a transformable attribute and store the data as either the array or dictionary you unpack from the JSON. It isn't very efficient accessing this attribute directly (you will incur an archiving overhead) so you should add a transient attribute to cache the value after first access.

Upvotes: 1

Related Questions