Skip to content

Using enums as types

Tom Harrington edited this page Apr 27, 2019 · 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, EventType) {
  Party,
  Concert,
  TradeShow
  };

Or in Swift:

@objc enum EventType : UInt16 {
  case party
  case concert
  case tradeShow
}

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 (EventType) as value.


See also Core Data User Info Keys