D/Objective-C 64bit

Jacob Carlborg via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Nov 18 05:59:18 PST 2014


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


More information about the Digitalmars-d-announce mailing list