我在CoreData中添加新实体时遇到问题。在我的模型中是Glyph - >轮廓 - >节点,每个节点都有origin,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具有正确的节点值。 有什么想法吗?
答案 0 :(得分:0)
自动释放问题?这个订单有效:
node.origin = [NSEntityDescription insertNewObjectForEntityForName:@"PointData" inManagedObjectContext:moc ];
node.origin.pointValue = NSMakePoint(point.x, point.y);