NSData from a custom object
问题 I'm working on client/server application which uses AsyncSocket. For transferring data, it uses NSData . 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? 回答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