Best way to implement Enums with Core Data

前端 未结 9 1542
天命终不由人
天命终不由人 2020-11-28 17:55

What is the best way to bind Core Data entities to enum values so that I am able to assign a type property to the entity? In other words, I have an entity called Item<

9条回答
  •  有刺的猬
    2020-11-28 18:35

    I set the attribute type as 16 bit integer then use this:

    #import 
    
    enum {
        LDDirtyTypeRecord = 0,
        LDDirtyTypeAttachment
    };
    typedef int16_t LDDirtyType;
    
    enum {
        LDDirtyActionInsert = 0,
        LDDirtyActionDelete
    };
    typedef int16_t LDDirtyAction;
    
    
    @interface LDDirty : NSManagedObject
    
    @property (nonatomic, strong) NSString* identifier;
    @property (nonatomic) LDDirtyType type;
    @property (nonatomic) LDDirtyAction action;
    
    @end
    

    ...

    #import "LDDirty.h"
    
    @implementation LDDirty
    
    @dynamic identifier;
    @dynamic type;
    @dynamic action;
    
    @end
    

提交回复
热议问题