On 24 Jun, 2014, at 9:14 am, Quincey Morris 
<quinceymor...@rivergatesoftware.com> wrote:

> On Jun 23, 2014, at 17:30 , Graham Cox <graham....@bigpond.com> wrote:
> 
>> I interpret that to mean it must call a designated initializer *eventually*, 
>> not necessarily directly. Since all -initXXX methods of the superclass must 
>> call the superclass's designated initializer, your subclass's D.I. can call 
>> any of the superclass's -initXXX methods.
> 
> Actually, I understood the thrust of Sean’s question as being that 
> NSWindowController’s initializers don’t follow Swift rules.
> 
> If you look in the Swift book, you’ll see that convenience constructions may 
> only call “across” (that is, call an initializer in the same class), while 
> designated constructors may only call “up” (to a *designated* initializer in 
> the superclass).
> 
> In that regard, ‘initWithWindowNibName:’ must be a designated initializer, 
> since subclasses that don’t do their own nib loading have nothing else to 
> call “up” to.
> 
> I assume, therefore, that ‘initWithWindowNibName:’ is marked as a designated 
> initializer in 10.10, though I haven’t looked to check this.
> 

You knew I'd have to look didn't you :)

It's .. not (see below). However there's the Automatic Initializer Inheritance 
rules which say that if the subclass doesn't define any designated initializers 
it inherits them, and if it has implementations of all the designated 
initializers it inherits the convenience ones as well. I think by that 
inheritance you get enough stuff inherited to allow you to call 
initWithWindowNibName:. 

Could probably test that in a playground by implementing a designated 
initializer to break the automatic inheritance and seeing what you then can't 
do. 

Nobody said Swift was simple. 

/* Designated Initializer.  window can be nil.  All other -init... methods call 
this, and then possibly do other setup.
 */
- (instancetype)initWithWindow:(NSWindow *)window NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

/* Instances initialized with the "Name" methods will eventually locate their 
nib file in the file's owner's class' bundle or in the app's +mainBundle using 
standard NSBundle API.  Use the "Path" method if your nib file is at a fixed 
location (which is not inside one of those bundles).
 */
- (instancetype)initWithWindowNibName:(NSString *)windowNibName;        // self 
is the owner
- (instancetype)initWithWindowNibName:(NSString *)windowNibName 
owner:(id)owner; // The owner is NOT retained
- (instancetype)initWithWindowNibPath:(NSString *)windowNibPath owner:(id)owner;


_______________________________________________

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