Gold Challenge -- simple solution


#1

My solution is very simple. I made a subclass of Line named Circle. A circle is nothing but a curved line after all. A circle can be described by 2 points, the challenge requires these be the bounding corners. So this class does not really need to declare any properties or methods. Since Circles are Lines I store them in completedLines. Then, in TouchDrawView I added a property:

@property (nonatomic) Circle *circleInProcess;;

In touchesBegan:withEvent:, before the touches loop, I test whether the are exactly 2 touches. If there are, this is circle drawing so circleInProcess gets a new Circle. In touchesMoved:withEvent: if there is a circleInProcess, and the touches are 2, again, before the loop, the circle is updated instead of the lines.

In drawRect: inside the loop, before drawing the line, I test if the line is really a circle. If it is, I draw an ellipsis instead of a line.