Writing Mistakes and Omission

There are some mistakes in this chapter so if you follow according to text you will get stuck

  1. The first one is that you cannot use DrawView as the rootview of the project as DrawView is the instance of the UIView not ViewController so you need to use the default ViewController.swift file as the root view controller

  2. In the ViewController.swift set the view to DrawView like this
    override func loadView() { super.loadView() drawView = DrawView() view = drawView view.backgroundColor = UIColor.white }

  3. You need to create a constructor in the Line.swift file like this
    init(begin: CGPoint, end: CGPoint){ self.begin = begin self.end = end }

I disagree. I think the chapter is correct.

  1. You’re asked to select the view of the view controller, not ViewController itself. When you do so, you can select a custom class that is a subclass of UIView. To make sure you’re selecting the view and not the view controller, select the view from the Document Outline. If properly selected, when you click on the Identity Inspector, you should see UIView greyed out as the default value for the Custom Class.
  2. Follow the previous point and you avoid setting up ViewController.view in the ViewController.swift file.
  3. As mentioned in the book, structs get a member-wise initializer if no other initializers are declared. If you remove that declaration, you get it for free. See “Memberwise Initializers for Structure Types” under The Swift Programming Language: Classes and Structures.
1 Like

Agree with you. And even add that in the solution discussed in the book everything is out of the box because if you set custom view to the root view in storyboard you don’t need to write a line of code to get the default view configuration and structs have built-in memberwise initializers.