November 2013
Beginner
325 pages
9h 47m
English
Objective-C programmers call accessor methods a lot. When properties were introduced, Apple also introduced a shorthand dot notation for calling those accessors.
Many Objective-C programmers prefer dot notation because it is easier to type. In main.m, try out dot notation:
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create an instance of BNRPerson
BNRPerson *mikey = [[BNRPerson alloc] init];
// Give the instance variables interesting values using setters
[mikey setWeightInKilos:96];
[mikey setHeightInMeters:1.8];
mikey.weightInKilos = 96;
mikey.heightInMeters = 1.8;
// Log the instance variables using the getters
float height = [mikey heightInMeters];
int weight = [mikey weightInKilos];
float height ...Read now
Unlock full access