Build crashes on page 240


#1

I keep trying to test it but as soon as i let go of the line it crashes. Does anybody know where the issue is in my code?

DrawView.m

[code]#import “SOCDrawView.h”
#import “SOCLine.h”

@interface SOCDrawView ()

@property (nonatomic, strong) SOCLine *currentLine;
@property (nonatomic, strong) NSMutableArray *finishedLines;

@end

@implementation SOCDrawView

-(instancetype)initWithFrame:(CGRect)r
{
self = [super initWithFrame:r];

if(self)
{
    self.finishedLines = [[NSMutableArray alloc] init];
    self.backgroundColor = [UIColor grayColor];
}
return self;

}

-(void)strokeLine:(SOCLine *)line
{
UIBezierPath *bp = [UIBezierPath bezierPath];
bp.lineWidth = 10;
bp.lineCapStyle = kCGLineCapRound;

[bp moveToPoint:line.begin];
[bp addLineToPoint:line.end];
[bp stroke];

}

-(void)drawRect:(CGRect)rect
{
[[UIColor blackColor] set];
for (SOCLine *line in self.finishedLines)
{
[self strokeLine:line];
}

if(self.currentLine)
{
    [[UIColor redColor] set];
    [self strokeLine:self.currentLine];
}

}

-(void)touchBegan:(NSSet *)touches
withEvent:(UIEvent *)event
{
UITouch *t = [touches anyObject];

CGPoint location = [t locationInView:self];

self.currentLine = [[SOCLine alloc] init];
self.currentLine.begin = location;
self.currentLine.end = location;

[self setNeedsDisplay];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *t = [touches anyObject];
CGPoint location = [t locationInView:self];

self.currentLine.end = location;

[self setNeedsDisplay];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.finishedLines addObject:self.currentLine];

self.currentLine = nil;

[self setNeedsDisplay];

}

[/code]


#2

I went throughout the rest of the chapter to see if I could find a fix, and by the time I had finished the chapter the bug was still there. I checked it with the solutions and all of the code is identical but it still doesn’t work. any advice?


#3

Could you post the error message you are getting?