I tried converting my objects to instances of NSData, putting them in an NSArray and storing the array in user defaults. I also tried putting the objects in an NSArray, converting the array to an instance of NSData and storing it in user defaults. Both ways I get the following error:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GelirObject encodeWithCoder:]: unrecognized selector sent to instance 0x89dbf90"
The name of my custom object is GelirObject.
I know that custom objects cannot be stored to user defaults directly. That's why I used NSData, but still I get this error. How can I store my objects without getting error?
Well first of all, it's just wrong what you are doing. You shouldn't put a lot of information inside your
NSUserDefaults
. As for the issue:Your
GelirObject
doesn't comply with theNSCoding
protocol. That's the reason your app is screaming. Just implement the required methodsinitWithCoder:
andencodeWithCoder:
.