core data - problem with automatically filled-in index

Discussion in 'Mac Programming' started by schoeringhumer, Sep 6, 2009.

  1. schoeringhumer macrumors newbie

    Joined:
    Sep 2, 2009
    #1
    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
     
  2. schoeringhumer thread starter macrumors newbie

    Joined:
    Sep 2, 2009
    #2
    ... here is the picture ... sry for second post
     

    Attached Files:

  3. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    You could do it with a custom add method when new rows are added to the table. As in:

    Code:
    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.
     

Share This Page