Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c enum class

I'm trying to create a enumeration class in objective-c. Here below is what I already got.

#import <Foundation/Foundation.h>

typedef enum  {
    Car,
    Bike,
    Boat
} Vehicle;

@interface ModelVehicle : NSObject {

    Vehicle vehicle;

}

@property (nonatomic) Vehicle vehicle;

@end

Now I can access the enum from another class but only with the following code. Why can't I access it with the class name where the enum in exists, for example ModelVehicle.Car?

Vehicle *hi = Car;
like image 277
Flappy Avatar asked Sep 25 '26 13:09

Flappy


1 Answers

In Objective-C, enums aren't a part of a class, so you reference them directly by name.

like image 196
mipadi Avatar answered Sep 28 '26 22:09

mipadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!