Re: How to instantiate WindowController in xib
Re: How to instantiate WindowController in xib
- Subject: Re: How to instantiate WindowController in xib
- From: Kyle Sluder <email@hidden>
- Date: Wed, 30 Nov 2016 12:27:28 -0600
On Tue, Nov 22, 2016, at 12:20 PM, Gerriet M. Denkmann wrote:
>
> > On 23 Nov 2016, at 01:02,Andy Lee <email@hidden> wrote:
> >
> >
> > On Tue, Nov 22, 2016, at 09:45 AM, Stéphane Sudre wrote:
> >> the windowNibName property should be set by your subclass of NSWindowController (by implementing the - (NSString *) windowNibName; method usually).
> >>
> >
> > You can also specify it in IB by going to the Identity Inspector (Command-Option-3 — the pane where you specify the object's Custom Class) and adding to "User Defined Runtime Attributes", using windowNibName as the key path and the nib name as the value.
>
> This is very good to know. I had the feeling that this should be possible
> in Xcode.
>
> In my case I had to subclass NSWindowController anyway.
> But this will be really useful where this is not the case.
>
> Thank you very much for this hint!
Do not do this. windowNibName is a read-only property. This only happens
to work because User-Defined Runtime Attributes are set via Key-Value
Coding, and KVC is able to find the underlying _windowNibName ivar.
Since ivars are private (despite being listed in the header file for the
sake of the fragile ObjC runtime), you cannot rely on this working in
the future.
Furthermore, even if windowNibName were a read-write property, I’d be
cautious about this. Like -awakeFromNib, the order in which UDRAs are
applied is not guaranteed; it’s possible that unarchiving could cause
File’s Owner or some other top-level object to cause the Window
Controller to try to load its window. If the windowNibName hasn’t been
set at that point, it will fail.
It is very rare to use an NSWindowController without a 1:1 relationship
between a subclass and a NIB. For best results, I would adhere to the
long-standing pattern of overriding -windowNibName.
--Kyle Sluder
>
>
> Kind regards,
>
> Gerriet.
_______________________________________________
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