问题描述
我正在使用AsyncSocket的客户端/服务器应用程序。对于传输数据,它使用 NSData
。
I'm working on client/server application which uses AsyncSocket. For transferring data, it uses NSData
.
如何插入我的自定义对象,包含 NSNumber
s, NSInteger
s和 NSString
>
How can I insert my custom object, containing NSNumber
s, NSInteger
s, and NSString
s into an NSData
object and then get it back out?
推荐答案
插入(序列化)自定义对象转换为NSData对象就是使用NSCoding和NSKeyedArchiver。
One way to insert (serialize) a custom object into an NSData object is to use NSCoding and NSKeyedArchiver.
首先,让您的自定义对象实现NSCoding协议。
示例:
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
然后,有关信息有关使用NSKeyedArchiver对象的信息,请参阅:
Then, for information on using your object with NSKeyedArchiver refer to:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Articles/creating.html
希望帮助!
这篇关于来自自定义对象的NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!