It's a property with a closure (a function, or better: a code block, taking a CGContext
as argument in this case). It does nothing. It ignores the CGContext
(that's the _ in
part).
Later in the example there's this function:
public func showCoreGraphicsDiagram(title: String, draw: (CGContext)->()) {
let diagramView = CoreGraphicsDiagramView(frame: drawingArea)
diagramView.draw = draw
diagramView.setNeedsDisplay()
XCPlaygroundPage.currentPage.liveView = diagramView
}
where you can provide another closure (CGContext) -> ()
, then this new closure is assigned to the draw
property.
And in the drawRect
function it's invoked: draw(context)
.
So, basically you can provide a code block that draws something, for example
showCoreGraphicsDiagram("Diagram Title", draw: { context in
// draw something using 'context'
})
or even shorter with the "trailing closure syntax":
showCoreGraphicsDiagram("Diagram Title") { context in
// draw something using 'context'
}