CoreData - can't set empty string as default value for attribute

后端 未结 8 846
鱼传尺愫
鱼传尺愫 2021-02-06 22:08

I have an entity in my datamodel with a string attribute that is currently optional, and I\'d like to convert this to a required attribute with a default value of the empty stri

8条回答
  •  清酒与你
    2021-02-06 22:32

    You can do it manually. In your model class, override awakeFromInsert and set your strings to empty string

    Swift:

    override func awakeFromInsert()
    {
        super.awakeFromInsert()
        self.stringProperty = ""
    }
    

    Objective-C

    - (void) awakeFromInsert
    {
        [super awakeFromInsert];
        self.stringProperty = @"";
    }
    

提交回复
热议问题