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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.