Skip to content

Using enums as types

Philippe Casgrain edited this page Dec 25, 2015 · 6 revisions

If you want to use a enum type for one of your scalar attribute (instead of using uint8_t or any other scalar type internally used by CoreData):

Declare your enum in a header file.

In ObjC:

// MyEnum.h
typedef NS_ENUM(uint16_t, Gender) {
  GenderMale,
  GenderFemale
};

Or in Swift:

enum Gender : UInt16 {
  case Male, Female
}

Specify the header file to import

Add the additionalHeaderFileName key in your Entity's UserInfo and give it that file name (MyEnum.h) as value.

Specify the type of your attribute

Add the attributeValueScalarType key in your Attribute's userInfo and give it the enum name (Gender) as value.


See also Core Data User Info Keys

Clone this wiki locally