On Sun, Sep 21, 2008 at 11:21 PM, D.K. Johnston <[EMAIL PROTECTED]> wrote: > I wrote a class that conforms to the NSCoding protocol. I used > encodeObject:forKey and decodeObjectForKey: in the required methods. > > By mistake I used NSArchiver to archive one of the class instances. It > compiled with no trouble; but then, not surprisingly, I got an exception > when I ran it: > > *** Terminating app due to uncaught exception 'NSInvalidArgumentException' > reason: '*** -encodeObject:forKey: only defined for abstract class. Define > -[NSArchiver encodeObject:forKey:]!' > > The fact that I should have used NSKeyedArchiver instead of NSArchiver isn't > obvious from the message. (At least it's not obvious to me.) Can anything > be done to ensure users of the class use NSKeyedArchiver, besides putting a > comment in the header file?
A comment in the header is a pretty good way to go, and a fairly standard technique. Understanding the error you saw will get easier with time. It's telling you that you're sending a message to an object that doesn't understand it. Some inspection shows that it's a keyed archiving message, and you're sending it to NSArchiver, so the rest flows from there. Now I don't doubt that it was non-obvious for you the first time around, but you'll probably only have that difficulty once. However, for extra paranoia, Mike Abdullah's technique of checking explicitly can let you give yourself a better error message. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]