Re: NSCoding protocol
Re: NSCoding protocol
- Subject: Re: NSCoding protocol
- From: "Michael Ash" <email@hidden>
- Date: Sat, 11 Oct 2008 14:37:42 -0400
On Fri, Oct 10, 2008 at 12:52 PM, Negm-Awad Amin <email@hidden> wrote:
> Yup, you are complelty right. The correct code:
>
> if( [BaseClass instancesRepondsToSelector@selector( initIWithCoder: )] ) {
> …
If you want to get really fun, you can check it thus:
if([super.class instancesRespondToSelector:...])
This works because the 'super' keyword just gives you a struct of type
objc_super, and you can access its members directly. (Note that in
ObjC++ you will have to use super.super_class instead.) The advantage
here is that you aren't hardcoding the name, so if you change what
class you derive from the code will continue to work as intended.
And before anyone jumps in, [self superclass] will *not* work, because
it fails if 'self' is an instance of a subclass of your class.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden