November 2013
Beginner
325 pages
9h 47m
English
Key-value coding is the ability to read and set a property using its name. The key-value coding methods are defined in NSObject, and thus every object has this capability.
Open main.m and find the line:
[a setProductName:@"Washing Machine"];
Rewrite the same line to use key-value coding:
[a setValue:@"Washing Machine" forKey:@"productName"];
In this case, the setValue:forKey: method, as defined in NSObject, will go looking for a setter method named setProductName:. If the object does not have a setProductName: method, it will access the instance variable directly.
You can also read the value of a variable using key-value coding. Add a line to main.m that prints out the product name:
int main (int ...
Read now
Unlock full access