DEV Community

Discussion on: Tracer, a Swift Drawing View, from Concept to CI

Collapse
 
jrtibbetts profile image
Jason R Tibbetts

This is a good writeup. I do have a couple notes about your style. I see several examples like

var expectedPath: Array<CGPoint> {
    get { return _expectedPath }
    set {
        _expectedPath = newValue
        drawExpectedPath(points: newValue)
    }
}

Since your getters don't have any side effects, these computed properties can just use didSet to make things simpler:

var expectedPath: Array<CGPoint> {
    didSet {
        drawExpectedPath(points: newValue)
    }
}

You don't have to deal with the _ variables or newValues.

And while we're using this example, it's much more idiomatic to declare Arrays and Dictionaries using [Type] and [KeyType: ValueType], respectively, so the previous example becomes

var expectedPath: [CGPoint] {
    didSet {
        drawExpectedPath(points: newValue)
    }
}

I've issued a PR for your project with these changes. Let me know what you think!

Collapse
 
jamiely profile image
Jamie Ly

Thanks Jason! I learned some new things!