NSData from a custom object

。_饼干妹妹 提交于 2019-12-23 18:38:08

问题


I'm working on client/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?


回答1:


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!



来源:https://stackoverflow.com/questions/6833413/nsdata-from-a-custom-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!