Reputation: 13286
When a user uploads something via my app, I create an ASIFormDataRequest object to make the POST.
When the user is offline, I would like to write a ASIFormDataRequest object to file and send it later.
Is there a built in way to serialize an object like this in Objective C, or do I have to write something from scratch?
Upvotes: 4
Views: 9195
Reputation: 243146
Yep! There's a really great thing called the NSCoding
protocol. A writeup on how to implement and use it is available on our local CocoaHeads site: http://cocoaheads.byu.edu/wiki/nscoding In a nutshell, you implement two methods to define what you want to save and how to restore it, and then it's a one-liner to actually archive your object.
Upvotes: 12
Reputation: 6329
In the Objective-C programming language, serialization (more commonly known as archiving) is achieved by overriding the write: and read: methods in the Object root class.
http://en.wikipedia.org/wiki/Serialization#Objective-C
There's a code example there too :-)
Upvotes: 2