1

I am working on an inherited codebase and trying to resolve the following warnings:

Designated initializer should only invoke a designated initializer on 'super'

Designated initializer missing a 'super' call to a designated initializer of the super class

The code is:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [self initWithFrame:[CDCUtility getScreenBounds]]; //switching to super breaks
    if (self) {
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setArray:[NSMutableArray new]];
        [self setButtonArray:[NSMutableArray new]];
        _graphicEQ = [[CDCEffectsGraphicEQ alloc] initWithFrame:CGRectMake((1024 / 2) - (811 / 2), 60, 860, 255)];
        [self addSubview:_graphicEQ];
        [_graphicEQ setDelegate:self];
        [self addBypassButtonToView];
        [self addFlatButtonToView];
        [self addScrollView];
    }
    return self;
}

So from what I can make out the developer overrode the superclass initWithCoder: (This is a UIView) to allow the custom UI to be loaded, and passed in this initWithFrame: parameter using custom arguments to create the view.

I have seen some say change the [self initWithFrame:]' in initWithCoder: to [super initWithFrame:] which does resolve the warnings, however it also bypasses calling the features necessary here to load the view correctly.

It works fine as is; I just wanted to cut down all possible warnings, so I wondered if changes can be made to resolve this?

Community
  • 1
  • 1
jcad
  • 63
  • 9

1 Answers1

1

Try this:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self designatedInitializer];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self designatedInitializer];
    }
    return self;
}

- (void) designatedInitializer {
    [self setArray:[NSMutableArray new]];
    [self setButtonArray:[NSMutableArray new]];
    _graphicEQ = [[CDCEffectsGraphicEQ alloc] initWithFrame:CGRectMake((1024 / 2) - (811 / 2), 60, 860, 255)];
    [self addSubview:_graphicEQ];
    [_graphicEQ setDelegate:self];
    [self addBypassButtonToView];
    [self addFlatButtonToView];
    [self addScrollView];
}
Sargis
  • 1,196
  • 1
  • 18
  • 31
  • partially works but i loose things like background colours and some other styling, any idea why? i assume the superclass is now setting frame elements that i dont want – jcad Apr 21 '17 at 11:46