0

CoreDataに新しいエンティティを追加する際に問題が発生しました。私のモデルでは、グリフ->輪郭->ノードで、各ノードには起点、bcpIn、bcpOutがあります-すべてPointValueクラスです。新しいオリジン、bcpInおよびbcpOutでノードを追加しようとしています。しかし、それらを作成し、関係を割り当てた後

origin.node = node;
bcpIn.node = node;
bcpOut.node = node;

bcpInのみが適切な値を持っています。OriginとbcpOutのノード値がnilですこれは私のコードの一部です:

 [points willChangeValueForKey:@"selectedObjects"];

 TPGlyph * glyph;
 TPContour * contour;

 if (points.selectedObjects.count==1) {
                TPPointData * currentPoint = [points.selectedObjects objectAtIndex:0];
                contour = currentPoint.node.contour;
                glyph = currentPoint.node.contour.glyph;
                //index = contour



  } else if (points.selectedObjects.count==0){
                glyph = [glyphs.selectedObjects objectAtIndex:0];
                contour = [NSEntityDescription insertNewObjectForEntityForName:@"Contour" inManagedObjectContext:moc];
                contour.glyph = glyph;  
            }

  TPNode * node = [NSEntityDescription insertNewObjectForEntityForName:@"Node" inManagedObjectContext:moc];

  node.contour=contour;
  node.type = [NSNumber numberWithInt:NSLineToBezierPathElement];

  NSPoint point = [self rezoomPoint: firstClick ofGlyph:glyph];

  TPPointData * origin = [NSEntityDescription insertNewObjectForEntityForName:@"PointData" inManagedObjectContext:moc ];
  origin.pointValue = NSMakePoint(point.x, point.y);
  origin.node = node;
  node.origin = origin;

  TPPointData * bcpOut = [NSEntityDescription insertNewObjectForEntityForName:@"PointData" inManagedObjectContext:moc ];
  bcpOut.pointValue = NSMakePoint(point.x, point.y);
  bcpOut.node = node;
  node.bcpOut = bcpOut;

  TPPointData * bcpIn = [NSEntityDescription insertNewObjectForEntityForName:@"PointData" inManagedObjectContext:moc];
  bcpIn.pointValue = NSMakePoint(point.x, point.y);
  bcpIn.node = node;
  node.bcpIn = bcpIn;

  [points didChangeValueForKey:@"selectedObjects"];

  [contour addNodesObject:node];
  [points addObject:origin];
  NSLog(@"contour %@", contour);
  NSLog(@"node %@", node);
  NSLog(@"origin %@", origin);
  NSLog(@"bcpIn %@", bcpIn);
  NSLog(@"bcpOut%@", bcpOut);

そして、出力は次のとおりです。

2013-02-01 09:50:04.410 AlwaysSmooth[59268:403] contour <TPContour: 0x1006c64e0> (entity: Contour; id: 0x105a07fc0 <x-coredata:///Contour/t338CE27E-8294-4455-AB79-BA5A70DD59AD2> ; data: {
    glyph = "0x100681350 <x-coredata://1CE61895-49D8-4BAB-BFE9-FC5762336779/Glyph/p2>";
    nodes =     (
        "0x100154e30 <x-coredata:///Node/t338CE27E-8294-4455-AB79-BA5A70DD59AD3>"
    );
})
2013-02-01 09:50:04.410 AlwaysSmooth[59268:403] node <TPNode: 0x1001aa0e0> (entity: Node; id: 0x100154e30 <x-coredata:///Node/t338CE27E-8294-4455-AB79-BA5A70DD59AD3> ; data: {
    bcpIn = "0x1001a8cf0 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD6>";
    bcpOut = "0x1001a9f60 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD5>";
    contour = "0x105a07fc0 <x-coredata:///Contour/t338CE27E-8294-4455-AB79-BA5A70DD59AD2>";
    next = "(...not nil..)";
    origin = "0x1001a8cf0 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD6>";
    prev = "(...not nil..)";
    smooth = 1;
    type = 1;
})
2013-02-01 09:50:04.411 AlwaysSmooth[59268:403] origin <TPPointData: 0x1001ee690> (entity: PointData; id: 0x1001c8d50 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD4> ; data: {
    node = nil;
    x = "-1936.5";
    y = "-981.8333";
})
2013-02-01 09:50:04.411 AlwaysSmooth[59268:403] bcpIn <TPPointData: 0x1001a8c90> (entity: PointData; id: 0x1001a8cf0 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD6> ; data: {
    node = "0x100154e30 <x-coredata:///Node/t338CE27E-8294-4455-AB79-BA5A70DD59AD3>";
    x = "-1936.5";
    y = "-981.8333";
})
2013-02-01 09:50:04.412 AlwaysSmooth[59268:403] bcpOut<TPPointData: 0x1001a9e80> (entity: PointData; id: 0x1001a9f60 <x-coredata:///PointData/t338CE27E-8294-4455-AB79-BA5A70DD59AD5> ; data: {
    node = nil;
    x = "-1936.5";
    y = "-981.8333";
})

originとbcpOutはnilですが、bcpInには適切なノード値があります。何か案は?

4

1 に答える 1

0

自動解放の問題?この順序は次のように機能します。

node.origin = [NSEntityDescription insertNewObjectForEntityForName:@"PointData" inManagedObjectContext:moc ];
node.origin.pointValue = NSMakePoint(point.x, point.y);
于 2013-02-01T19:27:28.683 に答える