1

次の問題があります。

同じエンティティの要素間の関係の設定は機能しますが、2 つの異なるエンティティ間の関係はエラーになる傾向があります。保存しようとしたときのエラー出力は次のとおりです。

NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1550.)";

NSValidationErrorKey = responsible;

NSValidationErrorObject = "<Actor: 0x8876840> (entity: Actor; id: 0x8875210 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Actor/p2> ; data: {\n    belongings = \"<relationship fault: 0x8a0c660 'belongings'>\";\n    name = Sofie;\n    orderingValue = 2;\n    performsA = \"<relationship fault: 0x8a190d0 'performsA'>\";\n    performsC = \"<relationship fault: 0x8a19110 'performsC'>\";\n    performsI = \"<relationship fault: 0x8a19150 'performsI'>\";\n    performsR = \"<relationship fault: 0x8a19190 'performsR'>\";\n    responsible =     (\n        \"0x8884e10 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Goal/p1>\"\n    );\n    supervisedBy = \"<relationship fault: 0x8a191f0 'supervisedBy'>\";\n    supervising = \"<relationship fault: 0x8a19230 'supervising'>\";\n    type = Person;\n})";

NSValidationErrorValue = "Relationship 'responsible' on managed object (0x8876840) <Actor: 0x8876840> (entity: Actor; id: 0x8875210 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Actor/p2> ; data: {\n    belongings = \"<relationship fault: 0x8a0c660 'belongings'>\";\n    name = Sofie;\n    orderingValue = 2;\n    performsA = \"<relationship fault: 0x8a190d0 'performsA'>\";\n    performsC = \"<relationship fault: 0x8a19110 'performsC'>\";\n    performsI = \"<relationship fault: 0x8a19150 'performsI'>\";\n    performsR = \"<relationship fault: 0x8a19190 'performsR'>\";\n    responsible =     (\n        \"0x8884e10 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Goal/p1>\"\n    );\n    supervisedBy = \"<relationship fault: 0x8a191f0 'supervisedBy'>\";\n    supervising = \"<relationship fault: 0x8a19230 'supervising'>\";\n    type = Person;\n}) with objects {(\n    <NSManagedObject: 0x8885d60> (entity: Goal; id: 0x8884e10 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Goal/p1> ; data: {\n    concerning = \"<relationship fault: 0x8a1ba40 'concerning'>\";\n    conflictedBy = \"<relationship fault: 0x8a1c5c0 'conflictedBy'>\";\n    conflicting = \"<relationship fault: 0x8a1c600 'conflicting'>\";\n    higherLevelGoalAND = \"<relationship fault: 0x8a1c640 'higherLevelGoalAND'>\";\n    higherLevelGoalOR = \"<relationship fault: 0x8a1c680 'higherLevelGoalOR'>\";\n    lowerLevelGoalAND = \"<relationship fault: 0x8a1c6c0 'lowerLevelGoalAND'>\";\n    lowerLevelGoalOR = \"<relationship fault: 0x8a1c700 'lowerLevelGoalOR'>\";\n    name = \"Customer satisfaction\";\n    operationalization = \"<relationship fault: 0x8a1c740 'operationalization'>\";\n    orderingValue = 1;\n    responsibles =     (\n        \"0x8875210 <x-coredata://599B45F7-F346-4674-B1B9-5BAEBD575E74/Actor/p2>\"\n    );\n})\n)}";

これが私のコードの一部です:

Actor.h

...
@interface Actor (CoreDataGeneratedAccessors)
- (void)addResponsibleObject:(Goal *)value;

- (void)removeResponsibleObject:(Goal *)value;

- (void)addResponsible:(NSSet *)values;

- (void)removeResponsible:(NSSet *)values;
...

ActorOverview.h

...
@interface ActorOverview : NSObject

{

NSMutableArray *allActors;

NSMutableArray *actorFetch;

NSManagedObjectContext *context;

NSManagedObjectModel *model;

}
@property (nonatomic, retain) NSManagedObjectContext *context;
...
-(void)relationshipBetweenActor:(Actor *)a andEntity:(NSManagedObject *)e withInfo:(NSString *)info action:(NSString *)action;
...

(relationshipBetweenActor:andEntity:withInfo:action: 2 つのアクター間の関係を設定する場合は正常に機能します)

しかし、ゴールとアクターの関係を設定するために次のようにすると失敗します (「アクターは特定のゴールに対して責任を負います」)。

ActorZoomViewController.m 内

// Define the actor

ActorOverview *ao = [[ActorOverview alloc]init];

Actor *actorInZoom = [ao fetchActorWithOrderingValue:currentActor];



// Define the goal

GoalOverview *go = [[GoalOverview alloc]init];

NSArray *goals = [[GoalOverview defaultOverview]allGoals];

Goal *goalInZoom = [goals objectAtIndex:0];



// Adding a new relationship

[ao relationshipBetweenActor:actorInZoom andEntity:goalInZoom withInfo:@"" action:@"add"];



// Save

[[ActorOverview defaultOverview]saveChanges];

ActorOverview.m で relationshipBetweenActor:andEntity:withInfo:action: を呼び出すもの

-(void)relationshipBetweenActor:(Actor *)a andEntity:(NSManagedObject *)e withInfo:(NSString *)info action:(NSString *)action

{
NSEntityDescription *ed = [e entity];

 if([[ed name] isEqualToString:@"Goal"])

     {

         if([action isEqualToString:@"add"])

         {

             NSLog(@"NEW relationship between Actor: %@ and Goal: %@", [a name], [e name]);

             [a addResponsibleObject:e];            

         }

         if([action isEqualToString:@"remove"])

         {

             NSLog(@"REMOVED relationship between Actor: %@ and Goal: %@", [a name], [e name]);

             [a removeResponsibleObject:e];

         }

     }

}

保存時にエラーが発生します。

誰かアドバイスをくれませんか?

4

0 に答える 0