@ H2CO3 is right for your setter. A dynamic getter has the same underlying problem. You are trying to call [self n] , which is not in id . That is why it will not compile. (As @ H2CO3 notes, this will result in a warning, not an error, you all use -Werror , right?) But more importantly, even if it would It would be an infinite loop. self.n is just a call to [self n] , which will return to this function.
If you're looking for examples, you can download the code for chapter 20 of iOS 6 Programming Pushing the Limits . See the Person project for Person.m . Chapter 28 contains much more explanations on how to implement this feature if you are interested.
Please note that the correct name in ObjC is very important. Your class should be Bird , not Bird . Obtaining a naming convention under your belt is crucial before attempting to use additional features such as dynamic dispatch.
source share