Re: Creating NSViewController with -init.
Re: Creating NSViewController with -init.
- Subject: Re: Creating NSViewController with -init.
- From: Keary Suska <email@hidden>
- Date: Tue, 25 Mar 2014 08:22:33 -0600
On Mar 24, 2014, at 6:56 PM, Rick Mann wrote:
> On Mar 24, 2014, at 17:53 , Kyle Sluder <email@hidden> wrote:
>
>> On Mon, Mar 24, 2014, at 05:41 PM, Rick Mann wrote:
>>> I'm creating an NSViewController subclass by calling -init, and at no
>>> time passing a name for nibNameOrNil. According to the docs, this should
>>> result in an exception, but it's building my view based on the .xib of
>>> the same name without a problem.
>>
>> Where does the documentation say that? I can't find it. It would be
>> worthy of a docs bug since it differs from the implementation.
>>
>> --Kyle Sluder
>
> So, it doesn't precisely say that calling -init will result in an exception. For -initWithNibName:bundle:, it says:
>
> "If you pass in a nil for nibNameOrNil then nibName will return nil and loadView will throw an exception; in this case you must invoke setView: before view is invoked, or override loadView."
>
> Since calling -init never affords a chance to pass in a nib name, and therefore -nibName shouldn't have a value, I would expect -loadView to throw.
>
> Normally I implement -init in my subclass and have it call -initWithNibName:bundle: with the NIB's name, but I hadn't gotten around to that yet, and it was working fine, and I was curious.
The argument name tells it all: "nibNameOrNil" says that nil is a acceptable option. Why would it be named thus if a nil value would throw an exception? The answer, NSViewController does not load its xib on init, but lazily when the view is accessed (or -loadView) is called. Passing nil would be a logical option when, for instance, your NSViewController's view is not in a xib or is in a xib that it isn't responsible for loading.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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