Errata

Programming iOS 9

Errata for Programming iOS 9

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 61
Second paragraph of section "Designable views and inspectable properties"

The paragraph says: "If an instance of this UIView subclass appears in the nib, then its self-configuration methods, such as init(coder:) and willMoveToSuperView:, will be compiled and run and the nib editor prepares to prepare your view. For example, if your view's init(coder:) method adds a UILabel as a subview of this view, then the nib editor will show that label."

Perhaps surprisingly, this is not the case. The initializer that will run is init(frame:), not init(coder:). This is easily confirmed with a snippet such as:

@IBDesignable
class DesignableView: UIView {
let myColor: UIColor
override init(frame: CGRect) {
self.myColor = UIColor.redColor()
super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
self.myColor = UIColor.greenColor()
super.init(coder: aDecoder)
}

override func drawRect(rect: CGRect) {
super.drawRect(rect)
self.myColor.setFill()
UIBezierPath(rect: self.bounds).fill()
}
}

You will see a red rectangle, not a green one. If you remove the init(frame:) initializer in this snippet, the IBDesignable agent will crash.

Note from the Author or Editor:
This must be right, because the submitter has clearly tested it out, but I haven't tested yet. I'll take it under advisement, making a note in my copy of the manuscript. And of course this erratum will be here to help others; the submitter has explained the matter with utmost clarity.

Simon Kågedal Reimer  Jun 24, 2016