PDA

View Full Version : core data - problem with automatically filled-in index




schoeringhumer
Sep 6, 2009, 09:19 AM
hi,

i have a problem with a core data binding ....

i bound my lieferschein_id column with a indexed core data attribute which has as type integer 32

when i want to add a new entry to my application, i would want to automatically insert the id ... which would be in this context 1,2,3, ..... into the lieferschein_id column ....

does anybody know how i have to do to insert the id .... ? ...

in the binding ... the controller key is arrangedObjects and the Model Key Path is lieferschein_id ...


any ideas ? ....


thanks for helping,

schoeringhumer



schoeringhumer
Sep 6, 2009, 09:23 AM
... here is the picture ... sry for second post

Eraserhead
Sep 6, 2009, 11:18 AM
You could do it with a custom add method when new rows are added to the table. As in:

NSManagedObject *lastGSL = [[globalSpellLevelController arrangedObjects] lastObject];
int level;
if(lastGSL == nil){
level = 1;
}else{
level = [[lastGSL valueForKey:@"level"] intValue]+1;
}
NSManagedObject *newGSL = [globalSpellLevelController newObject];
[newGSL setValue:[NSNumber numberWithInt:level]
forKey:@"level"];
[globalSpellLevelController addObject:newGSL];

Alternatively you could do it properly in the init method for a custom subclass of NSManagedObject, though what you'd call to set it I don't know.