开发者

NSData from a custom object

开发者 https://www.devze.com 2023-03-23 14:43 出处:网络
I\'m working on cli开发者_开发技巧ent/server application which uses AsyncSocket. For transferring data, it uses NSData.

I'm working on cli开发者_开发技巧ent/server application which uses AsyncSocket. For transferring data, it uses NSData.

How can I insert my custom object, containing NSNumbers, NSIntegers, and NSStrings into an NSData object and then get it back out?


One way to insert (serialize) a custom object into an NSData object is to use NSCoding and NSKeyedArchiver.

First, have your custom object implement the NSCoding protocol.
Example here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Articles/codingobjects.html#//apple_ref/doc/uid/20000948-97234

Then, for information on using your object with NSKeyedArchiver refer to:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Articles/creating.html

Hope that helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消