That's my code at the moment:
class LineDrawer : NSView {
required init?(coder aDecoder : NSCoder) {
super.init(coder: aDecoder)
}
var line : Array<Line> = []
var lastPt : CGPoint!
override func mouseDown(theEvent: NSEvent) {
super.mouseDown(theEvent)
let location = theEvent.locationInWindow
println(location)
}
override func mouseDragged(theEvent: NSEvent) {
super.mouseDragged(theEvent)
var newPt = theEvent.locationInWindow
line.append(Line(start: newPt, end: lastPt))
lastPt = newPt
}
override func drawRect(dirtyRect: NSRect) {
}
}
class Line {
var start : CGPoint
var end : CGPoint
init(start _start : CGPoint, end _end : CGPoint) {
start = _start
end = _end
}
}
And I just don't have any ideas how to draw the line with a selected color (e.g. black) for each line in line array. I'm new to swift, so I'll be grateful for the comprehensive explanation.