Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serializing objects in Objective C

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?

like image 569
Andrew Johnson Avatar asked Dec 09 '22 18:12

Andrew Johnson


2 Answers

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.

like image 106
Dave DeLong Avatar answered Dec 24 '22 12:12

Dave DeLong


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

like image 40
David Claridge Avatar answered Dec 24 '22 11:12

David Claridge