UIView in Xcode 6

#1

I’m working through the Hypnosister problem and am asked to make a a BNRHypnosisView class which is a subclass of UIView. However, the book says that when this is created I should have two method stubs. However, none are there. I think Xcode 6 has removed them or doesn’t have the same classes, I’m not sure. Is there any work around for this, I’m currently stuck here.

#2

You mean you didn’t even get the (commented-out) drawRect: method?

//  MyView.m

#import "MyView.h"

@implementation MyView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
@end

Are you sure you did not miss something?

If you are getting a blank file only, this is highly unusual, you can type in the missing methods as shown in the book.

#3

You are right, it does give me the (commented-out) drawRect: method, however, the book says it should include a “initWithFrame” method and I think a property. I’m a bit unsure what is supposed to be there, I’m a newbie at this.

Can anyone tell me what should be in the UIView to make this portion of the chapter work? The book only mentions the methods should be there but doesn’t give the entire exact code that should be there.

#4

You can use:

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

Otherwise, if you encounter any other issues while using XCode 6. Download the solutions and check for the specified missing code.

Cheers,
Jan Marek

#5

I encountered this problem as well. At first I didn’t get anything in the file. The problem seemed to be that I manually typed UIView into the “Subclass of” field. When I let it autopopulate I got the commented-out drawRect method.

However, I still don’t get the initWithFrame method.