Silver solution


#1

If a line is selected, no other line can be drawn?
Unsure if this is really the most elegant solution ?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //let's put in a log statement to the se order of events
    NSLog(@"%@", NSStringFromSelector(_cmd));
    
    for (UITouch *t in touches) {
        if(self.selectedLine == nil)
        {
            CGPoint location = [t locationInView:self];
            BNRLine *line = [[BNRLine alloc]init];
            line.begin = location;
            line.end = location;
            NSValue *key = [NSValue valueWithNonretainedObject:t];
            self.linesInProgress[key] = line;
        }
    }
    [self setNeedsDisplay];
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    //Let's put in a log statement to see the order of events
    NSLog(@"%@", NSStringFromSelector(_cmd));
    for( UITouch * t in touches)
    {
        if(self.selectedLine == nil)
        {
            NSValue *key = [NSValue valueWithNonretainedObject:t];
            BNRLine *line = self.linesInProgress[key];
            line.end = [ t locationInView:self];
            
        }
    }
    [self setNeedsDisplay];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //log
    NSLog(@"%@", NSStringFromSelector(_cmd));
    for (UITouch * t in touches)
    {
        if(self.selectedLine == nil)
        {
            NSValue *key = [ NSValue valueWithNonretainedObject:t];
            BNRLine *line = self.linesInProgress[key];
            [self.finishedLines addObject:line];
            [self.linesInProgress removeObjectForKey:key];
        }
    }
    
    [self setNeedsDisplay];
}

#2

ahh, I came to the same solution as you after spending far too much time (days) on this silver challenge.
With all my other ideas a “DOUBLE TAP/hold drag” combination would still draw a new line while dragging.

I like it :slight_smile: