Accessing Properties Using the Dot Operator

The Objective-C language enables you to access properties using a more convenient syntax. To get the value of the numerator stored in myFraction, you could write this:

[myFraction numerator]

This sends the numerator message to the myFraction object, resulting in the return of the desired value. You can also write the following equivalent expression using the dot operator:

myFraction.numerator

The general format here is as follows:

instance.property

You can use a similar syntax to assign values as well:

instance.property = value

This is equivalent to writing the following expression:

[instance setProperty: value]

In Program 7.1, you set the numerator and denominator of your fraction to 1/3 using the ...

Get Programming in Objective-C, Sixth Edition 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.