Re: nibs don't respect protocols
Re: nibs don't respect protocols
- Subject: Re: nibs don't respect protocols
- From: Christiaan Hofman <email@hidden>
- Date: Wed, 2 Jun 2010 23:18:19 +0200
On Jun 2, 2010, at 20:27, Matt Neuburg wrote:
> I'm moving this over from Cocoa-Dev, so if you have the feeling you've seen
> this before, that's why.
>
> I'm struck by the following sort of situation. A UIApplication's delegate
> property is defined as an id <UIApplicationDelegate>. But if I hook up the
> UIApplication proxy object in a nib to another instance as its delegate, and
> if that other instance does _not_ formally adopt UIApplicationDelegate,
> there seems to be no penalty: the nib doesn't complain, and the app runs
> fine.
>
> So... Are nibs just ignorant of protocols? This feels like a bug. If you try
> to hook up an outlet to the wrong type (e.g. a UILabel instead of a declared
> UITextField), you can't; Interface Builder won't let you. Well, a class that
> doesn't declare conformance to UIApplicationDelegate *is* the wrong type for
> UIApplication's delegate; yet Interface Builder *does* let you. In that
> case, what's the point of having the protocol at all?
>
IB is indeed not checking protocols, only classes. Note that IB is ignorant in more ways, for instance it also does not know about informal categories in separate files.
Protocols are still useful when setting delegates (or whatever) programmatically. Or just as a matter of compiling to make sure your class implements the requires methods. But for NIBs they're indeed not functional, but that doesn't mean you should not be clear in your interfaces. I expect they will be checked somewhere in the future.
> I'd be willing to file a bug but I think I'd like some encouragement
> first... :) m.
>
I'm pretty confident it's a known bug, though I'm not really sure if it should be called a bug rather than an imperfection. IB is not a compiler, and protocol conformance is really a compiler check, it's not a syntactical requirement (as each object is really just an id). But of course more bug reports may move this up in the queue, and it would be a worthy feature. (Though for me I think reading categories would be more important, because it's in fact restricting what you can do rather than allowing too much.)
Christiaan
> --
> matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
> A fool + a tool + an autorelease pool = cool!
> AppleScript: the Definitive Guide - Second Edition!
> http://www.tidbits.com/matt/default.html#applescriptthings
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden