gpt4 book ai didi

objective-c - 删除对象时 CoreData 的奇怪行为

转载 作者:行者123 更新时间:2023-12-03 16:46:51 25 4
gpt4 key购买 nike

我尝试构建简单的贝塞尔曲线编辑器。型号和代码如下。当我尝试删除node.bcpInDatanode.bcpOutData时,仅node.originData被删除,女巫根本没有任何意义。

这是我的模型: enter image description here

这是删除:方法:

-(void) delete:(id)sender {

[undoManager beginUndoGrouping];
[points willChangeValueForKey:@"arrangedObjects"];

NSMutableArray * nodesToDelete = [NSMutableArray array];
for (TPPointData * pointData in points.selectedObjects) {


NSLog(@"PointData %@", pointData);
NSLog(@"PointData.node = %@", pointData.node);
TPNode * node = pointData.node;

if (pointData == pointData.node.originData) {
//delete everything
[nodesToDelete addObject:pointData.node];
if (pointData.node.bcpInData!=nil) {
NSLog(@"deleting bcpInData: %@", pointData.node.bcpInData);
[moc deleteObject:pointData.node.bcpInData];
pointData.node = nil;
}
if (pointData.node.bcpOutData!=nil) {
NSLog(@"deleting bcpOutData: %@", pointData.node.bcpOutData);
[moc deleteObject:pointData.node.bcpOutData];
pointData.node = nil;

}
NSLog(@"deleting originData: %@", pointData.node.bcpOutData);
[moc deleteObject:pointData];
pointData.node = nil;

} else { //delete just object

[moc deleteObject:pointData];
pointData.node = nil;
}
NSLog(@"node: %@", node);
}


NSMutableArray * contoursToDelete = [NSMutableArray array];
for (TPNode * node in nodesToDelete) {

if (node.contour.nodes.count == 1) {
[contoursToDelete addObject:node.contour];
}
[moc deleteObject:node];
}

for (TPContour * contour in contoursToDelete) {
[moc deleteObject:contour];
}
[points didChangeValueForKey:@"arrangedObjects"];
[undoManager endUndoGrouping];
}

尝试删除来源后的列表:

2013-02-03 12:11:34.849 AlwaysSmooth[42786:403] PointData <TPPointData: 0x105c06400> (entity: PointData; id: 0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "215.5";
y = "550.1667";
})
2013-02-03 12:11:34.850 AlwaysSmooth[42786:403] PointData.node = <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = "0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327>";
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
2013-02-03 12:11:34.851 AlwaysSmooth[42786:403] deleting bcpInData: <TPPointData: 0x100183d70> (entity: PointData; id: 0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "301.4023";
y = "544.7839";
})
2013-02-03 12:11:34.853 AlwaysSmooth[42786:403] deleting originData: (null)
2013-02-03 12:11:34.854 AlwaysSmooth[42786:403] node: <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = nil;
prev = "(...not nil..)";
smooth = 1;
type = 2;
})

为什么它甚至不尝试删除bcpOutDataoriginData 删除前为空。删除后,bcpInDatabcpOutData 仍然存在于节点对象中。撤消仍然是可能的。

当我尝试仅删除 bcpInDatabcpOutData 时,代码再次仅删除 originData:

2013-02-03 12:29:13.526 AlwaysSmooth[42786:403] PointData <TPPointData: 0x100183d70> (entity: PointData; id: 0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "301.4023";
y = "544.7839";
})
2013-02-03 12:29:13.527 AlwaysSmooth[42786:403] PointData.node = <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = "0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327>";
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
2013-02-03 12:29:13.529 AlwaysSmooth[42786:403] node: <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = nil;
prev = "(...not nil..)";
smooth = 1;
type = 2;
})

有什么帮助吗?

最佳答案

在点 Controller 中选择了 BcpInData 和 BcpOutData。这已经足够了[points removeSelectedObjects:@[pointData]]; 删除之前。

关于objective-c - 删除对象时 CoreData 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14672049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com