November 2013
Beginner
325 pages
9h 47m
English
Inside any method, you have access to the implicit local variable self. self is a pointer to the object that is running the method. It is used when an object wants to send a message to itself.
For example, many Objective-C programmers are quite religious about never reading or writing to an instance variable directly. They even call accessors within implementations of other methods in the same class.
Currently, your implementation of bodyMassIndex accesses the instance variables directly. In BNRPerson.m, update bodyMassIndex to use the accessor methods instead:
- (float)bodyMassIndex
{
return _weightInKilos / (_heightInMeters * _heightInMeters);
float h = [self heightInMeters];
return [self weightInKilos] / (h * h);
}
Read now
Unlock full access