I want to add a C++ Class object into NSUserDefaults
. If I add it directly, it crashes. How do I add c++ Class object to NSUserDefaults?
NSUserDefaults
supports some NSObject
-based classes to be encoded out of the box. Proper way to save custom NSObject
classes into NSUserDefaults
instance is to encode them into NSData
and save it.
In your case, since you have a C++ class, you could either wrap it's data to an NSObject
( NSDictionary
maybe) or implement a class <-> string serialisation and deserialisation, saving a string object into the NSUserDefaults
instance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.