> On Oct 18, 2014, at 20:33 , Graham Cox <graham....@bigpond.com> wrote:
> 
> According to the latest documentation pack that arrived on Thursday, Swift 
> has:
> 
> convenience init(windowNibName windowNibName: String,
>           owner owner: AnyObject)
> 
> So just use this. Like C++, Swift has overloaded method names, so 'init' can 
> take various parameter combinations.

I tried this:

16      override
17      init()
18      {
19              init(windowNibName: "foo", owner: self); 
20      }
21

But I get:

/Users/rmann/Projects/XCAM/repo/XNC/trunk/XNC/CommConfig.swift:19:7: 
Initializers may only be declared within a type
/Users/rmann/Projects/XCAM/repo/XNC/trunk/XNC/CommConfig.swift:19:23: Expected 
parameter type following ':'
/Users/rmann/Projects/XCAM/repo/XNC/trunk/XNC/CommConfig.swift:19:23: Expected 
',' separator
/Users/rmann/Projects/XCAM/repo/XNC/trunk/XNC/CommConfig.swift:21:1: 'required' 
initializer 'init(coder:)' must be provided by subclass of 'NSWindowController'

If I instead call super.init(...), I get:

/Users/rmann/Projects/XCAM/repo/XNC/trunk/XNC/CommConfig.swift:19:3: Must call 
a designated initializer of the superclass 'NSWindowController'

> Also, in general I think what you're saying about designated initializers is 
> incorrect - the designated initializer MUST be called, but not necessarily by 
> you. All it means is that the other init... methods must call it. The 
> guideline about it being the one with the most parameters is not a rule - 
> typically that's true but it's not a requirement and for many classes, 
> definitely not true.

In this case, it might've solved the problem (except that I can't refer to self 
yet).

> 
> 
> --Graham
> 
> 
> 
> 
> 
> On 19 Oct 2014, at 2:08 pm, Rick Mann <rm...@latencyzero.com> wrote:
> 
>> In Obj-C, I typically subclass NSWindowController and override -init to call 
>> -initWithNibName:. I do this so the caller doesn't have to worry about how 
>> to make one of these window controllers:
>> 
>> @implementation MyWindowController
>> 
>> - (id) init
>> {
>>   self = [super initWithWindowNibName: "MyWindow" owner: self]
>>   ...
>>   return self;
>> }
>> 
>> I can't figure out how to do the same in Swift. NSWindowController makes 
>> initWithWindow() the only designated initializer, which I must call, which 
>> makes it seem like I can't use any of the convenience methods. Apple's own 
>> guidance on designated inititalizers is that they should be the ones that 
>> take the most parameters.
>> 
>> So, I can load the nib myself, and make the window, and pass that up, but 
>> this seems broken. Is it?
> 
> 
> _______________________________________________
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/rmann%40latencyzero.com
> 
> This email sent to rm...@latencyzero.com


-- 
Rick Mann
rm...@latencyzero.com



_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to