Get error from - (instanceType)initWithFrame:(CGRect) frame


When I run the following method in BNRHypnosisView.m I get an error message:

- (instancetype) initWithFrame:(CGRect)frame { if (self) { // All BNRHypnosisViews start with a clear background color self.backgroundColor = [UIColor clearColor]; } return self; }

The error message reads:

This doesn’t make sense because bounds have been used to define the frame in the AppDelegate.m file.

When I comment out the above method, it runs fine, but of course, I cannot change the background to clear.



Yes, AppDelegate.m is defining the frame being passed to your initWithFrame: method, but it’s up to your method to do the actual initialization.

I recommend going back to study the section on initializers in Chapter 2, pages 49-55. It will be well worth your time.


OK, found out had left out the line:

self = [super initWithFrame:frame];

Now, works fine.

Thank you!


Super (no pun intended)! Glad you found what you needed, and why it’s necessary!