Issues causing draw functions in drawRect (CGRect) in Xcode playground

I have a playground setup for code validation. I usually split my drawing code into sections and call various functions from the drawRect () call of the UIView. On the playground, the call to another drawing function from drawRect () seems to go into an infinite loop. Here is the code:

class MyView: UIView {
    override func drawRect(rect: CGRect) {
        aCircle()
    }


    func aCircle()
    {
        let rect = CGRect(x: 20, y: 20, width: 100, height: 100 )
        var Path = UIBezierPath(ovalInRect: rect )
        UIColor.blackColor().set()
        Path.fill()

    }

}

let testView = MyView(frame: CGRect(x: 0, y: 0, width: 300, height: 300 ))
testView.backgroundColor = UIColor.whiteColor()

      

however if I strike out the aCircle () function from the class structure and call it from drawRect () it draws as expected, but if the function call is not placed above the class declaration it throws an error in the drawRect call where aCircle () is called

"Use of unresolved identifier 'aCircle'

      

Any suggestions for keeping the call on the UIView class. Thanks to

+3


source to share





All Articles