4

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?

1
  • I would say that trying to serialize the request object isn't the right solution to this problem. I would store the data contained in the request instead, and rebuild the request and send it when online. Commented Dec 7, 2009 at 4:09

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep the link is dead, an actual code example would be very appreciated.
For anyone else still coming here and looking for what Cocoaheads originally had up, here is an archived copy: web.archive.org/web/20130330051451/cocoaheads.byu.edu/wiki/…
2

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

3 Comments

huh, I've never heard of doing it that way
interesting.. maybe the Wikipedia page needs updating?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.