Drawing Data

Create a new file with the shortcut N and choose the Cocoa Touch Class template. In the Class text field, type in the name DiagramView and make it a subclass of UIView. Click Next and then click Create.

Xcode creates a subclass of UIView and fills it with some comments to get us started. Remove the lines with the comments and the multiline comment strings such that the class looks like this:

 class​ ​DiagramView​: ​UIView​ {
 override​ ​func​ ​draw​(_ rect: ​CGRect​) {

UIKit calls the draw method of a UIView subclass whenever the view is rendered on-screen. We have to put our drawing code into this method. But before we can draw data, we need to have it available ...

Get Build Location-Based Projects for iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.