On 2014-11-18 10:07, Christian Schneider wrote:
I'm wondering how I should deal with overriding "designated
initailizers". I really have no clue about the part "self = [super...].
KeyboardView is a subclass of NSView.

@implementation KeyboardView

- (id)initWithFrame:(NSRect)frame {
     self = [super initWithFrame:frame];
     if (self) {
         // Initialization code here.
     }
     return self;
}
@end


This is what I came up with so far:

override KeyboardView initWithFrame(NSRect frame) [initWithFrame:] {
     //my stuff
     return cast(KeyboardView) super.initWithFrame(frame) ;
}

This compiles and does not throw any runtime error, but it's a bit
against the idea, because in Objective-C the idea is to first call the
super class, then adapt and override what is necessary. When calling
super in the very end, this of course is no longer guaranteed.

Can't you just call "super" in the beginning of the method and then call return "this" at the end. Something like this:

override KeyboardView initWithFrame(NSRect frame) [initWithFrame:] {
    super.initWithFrame(frame);
    // my stuff
    return this;
}

--
/Jacob Carlborg
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Michel Fortin via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
            • Re: D... Michel Fortin via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
  • Re: D/Objective-C 64bit Martin Nowak via Digitalmars-d-announce

Reply via email to