views:

116

answers:

2

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?

A: 

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 :-)

David Claridge
huh, I've *never* heard of doing it that way
Dave DeLong
interesting.. maybe the Wikipedia page needs updating?
David Claridge
I actually saw this and originally thought all objects have a built in write method, but then I realized I had to write one if I wanted to do it this way.
Andrew Johnson
+3  A: 

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.

Dave DeLong