CoreData - Daten hinzufügen bei To Many Relationship

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • CoreData - Daten hinzufügen bei To Many Relationship

    Hallo Leute,

    kann mir mal jemand auf die Sprünge helfen.

    Ich habe eine simple App mit CoreData und zwei Enteties.

    Sieht so aus:
    osxentwicklerforum.de/index.ph…c821ca5eb108cd01d2cba7c54
    (To - Many Relationship)

    Für beide gibt es jeweils ein TableView. Da kann ich auch schön Daten hinzufügen, bearbeiten usw.


    Jetzt möchte ich im Code neue "Devices" hinzufügen. Unzwar in die "Enviroment", die gerade ausgewählt ist.

    Ichs schaffe das einfach nicht aus meinem AppController hinaus.


    Habe mir für beide Enteties die Klassen erzeugen lassen.

    Enviroment.m sieht so aus:

    PHP-Quellcode

    1. #import "Enviroment.h"
    2. #import "Device.h"
    3. @implementation Enviroment
    4. @dynamic name;
    5. @dynamic devices;
    6. - (void) awakeFromInsert
    7. {
    8. //Standard Enviroment Name:
    9. [self setValue:[NSString stringWithFormat:@"Untitled Enviroment"] forKey:@"name"];
    10. }
    11. - (void)addDevicesObject:(Device *)value {
    12. NSLog(@"eins");
    13. NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    14. [self willChangeValueForKey:@"devices" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    15. [[self primitiveValueForKey:@"devices"] addObject:value];
    16. [self didChangeValueForKey:@"devices" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    17. [changedObjects release];
    18. }
    19. - (void)removeDevicesObject:(Device *)value {
    20. NSLog(@"zwei");
    21. NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    22. [self willChangeValueForKey:@"devices" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    23. [[self primitiveValueForKey:@"devices"] removeObject:value];
    24. [self didChangeValueForKey:@"devices" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    25. [changedObjects release];
    26. }
    27. - (void)addDevices:(NSSet *)value {
    28. NSLog(@"drei");
    29. [self willChangeValueForKey:@"devices" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
    30. [[self primitiveValueForKey:@"devices"] unionSet:value];
    31. [self didChangeValueForKey:@"devices" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
    32. }
    33. - (void)removeDevices:(NSSet *)value {
    34. NSLog(@"vier");
    35. [self willChangeValueForKey:@"devices" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
    36. [[self primitiveValueForKey:@"devices"] minusSet:value];
    37. [self didChangeValueForKey:@"devices" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
    38. }
    39. @end
    Alles anzeigen


    Geht das vielleicht irgendwie darüber?

    Gruß
    Daniel
    “I want to see an elephant hunt down a man for the sole purpose of collecting his teeth, while a chorus of typewriters sings songs that praises the bananas for their wisdom, leadership, and their high levels of potassium.” ― Jarod Kintz, I Want