Question

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?

Was it helpful?

Solution

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:

NSData *incomeObjectData = [NSKeyedArchiver archivedDataWithRootObject:incomeObject];

Your GelirObject doesn't comply with the NSCoding protocol. That's the reason your app is screaming. Just implement the required methods initWithCoder: and encodeWithCoder:.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top