O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

30Properties

In the last chapter, you created a class called Appliance that had two properties: productName and voltage. Let’s review how those properties work.

In Appliance.h, you declared two instance variables to hold the data:

{​
 ​ ​ ​ ​N​S​S​t​r​i​n​g​ ​*​p​r​o​d​u​c​t​N​a​m​e​;​
 ​ ​ ​ ​i​n​t​ ​v​o​l​t​a​g​e​;​
}​

You also declared accessor methods for them. You could have declared the accessors like this:

-​ ​(​v​o​i​d​)​s​e​t​P​r​o​d​u​c​t​N​a​m​e​:​(​N​S​S​t​r​i​n​g​ ​*​)​s​;​
-​ ​(​N​S​S​t​r​i​n​g​ ​*​)​p​r​o​d​u​c​t​N​a​m​e​;​
-​ ​(​v​o​i​d​)​s​e​t​V​o​l​t​a​g​e​:​(​i​n​t​)​x​;​
-​ ​(​i​n​t​)​v​o​l​t​a​g​e​;​

However, you used the @property construct instead:

@​p​r​o​p​e​r​t​y​ ​(​c​o​p​y​)​ ​N​S​S​t​r​i​n​g​ ​*​p​r​o​d​u​c​t​N​a​m​e​;​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required