I don´t understand what I might be doing wrong here since I am following an instruction book – on setting the value calling a method of an class. I have #imported it, and everything should be fine. But Xcode complains: no know class method selector for “setWeightInKilos and “setHeightInMeters”. These instance methods are implemented in the “Person” class so I do not know why this happens.
Person *aPerson = [[Person alloc] init];
[Person setWeightInKilos:96];
[Person setHeightInMeters:1.8];
float bmi = [Person bodyMassIndex];
In Objective C, there are two types of methods. Class methods, which do not act on an object, but instead usually perform some task related to that TYPE of object. For example, there are built in methods to test for network connections, device capabilities, etc. These are always denoted with a “+” sign, and cannot be called on instances of objects, only the class itself.
The other type, instance methods, are MUCH more common, and act on objects that you instantiate or create yourself. These are the methods that you write in the implementation file with a “-” prefix. They are things like getters, setters, or methods that you have written yourself.
In your case, you need to call these setter methods on the instance of your Person object, not the Person class itself. It doesnt make sense to set the height or weight of the entire class (nor is it possible), since every object will need to have its own unique height and weight.
You need to call: