A basic init method

In some cases, an initial value of zero for your instance variables may work fine. In others, however, you will need instances of your class to come into the world with their instance variables initialized to non-zero values.

Let’s say that every instance of BNRAppliance should start its life with a voltage of 120. In BNRAppliance.m, override NSObject’s init method by adding a new implementation of init.

          -​ ​(​i​n​s​t​a​n​c​e​t​y​p​e​)​i​n​i​t​ {​ ​ ​ ​ ​/​/​ ​C​a​l​l​ ​t​h​e​ ​N​S​O​b​j​e​c​t​'​s​ ​i​n​i​t​ ​m​e​t​h​o​d​ ​ ​ ​ ​s​e​l​f​ ​=​ ​[​s​u​p​e​r​ ​i​n​i​t​]​;​ ​ ​ ​ ​/​/​ ​D​i​d​ ​i​t​ ​r​e​t​u​r​n​ ​s​o​m​e​t​h​i​n​g​ ​n​o​n​-​n​i​l​?​ ​ ​ ​ ​i​f​ ​(​s​e​l​f​)​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​/​/​ ​G​i​v​e​ ​v​o​l​t​a​g​e​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide 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.