Supposed I have a class called TrafficLight and I would like to have a property currentColor. I know that it’s possible to create an enum to represent the current color from a fixed pool of choices, like this:
enum currentColor { CurrentlyRed = 0, CurrentlyYellow = 1, CurrentlyGreen = 2 };
But now how do I turn this into an ivar in a Cocoa class? If I make it a property what are the property attributes that are typically used? Does the enum definition belong inside the implementation scope? Does it go inside of any particular method? (such as init?)
You can’t forward declare enums, so the definition should be in the interface file of the class, and the property is declared as (nonatomic, assign) with a type of your enum:
This way the class and the consumers of the class have access to the definition.