Core Data (Mac) How to implement auto increment on an ID field

前端 未结 2 1618
没有蜡笔的小新
没有蜡笔的小新 2021-02-11 01:29

I was wondering if anyone can point me in the direction of how to set up auto increment on an attribute in a coredata entity. I know the indexed check box just makes the field i

2条回答
  •  不思量自难忘°
    2021-02-11 02:13

    this is how apple implemented autoincrement:

     - (void) awakeFromInsert
         {
        [super awakeFromInsert];
        static int tempID = 0;
        [self setValue:[NSNumber numberWithInt:++tempID] forKey:@"id"];
    }
    

提交回复
热议问题