How to convert NSValue to NSData and back?

后端 未结 3 1318
旧巷少年郎
旧巷少年郎 2020-12-30 07:45

A have a number of NSValue (obtained via KVC valueForKey) that I need to append to an NSData object in order to send it over the netwo

3条回答
  •  [愿得一人]
    2020-12-30 08:37

    You can use NSCoder (like NSKeyedArchiver) to archive the data, then send the resulting NSData. On the other side you can unarchive it. There may be some caveats with this (for example http://www.cocoabuilder.com/archive/cocoa/82344-nskeyedarchiver-and-nsvalue.html) esepcially if you are wrapping structs and other non-archiving stuff in NSValue.

提交回复
热议问题