我有一个名为Node的类,它包含一组参数和一个名为subNodes的NSMutableArray。一个进程创建一个Node对象作为树的根,并使用subNodes数组创建一个大型的节点树。这整个树应该传递给另一个进程,所以我设置了一个NSConnection:
Node *tree;
// ...create Node-Tree...
NSConnection *otherProcess = [NSConnection connectionWithRegisteredName:@"MyApp"
host:nil];
MyObj *remoteObj = (MyObj*) [[otherProcess rootProxy] retain];
[remoteObj setNodeTree:tree];通信本身是有效的,远程方法'setNodeTree',它期望调用root-Node。但是,树的传输不起作用。我必须为Node类实现一个copyWithZone方法:
-(id)copyWithZone:(NSZone*)zone
{
Node *nodeCopy = [[[self class] allocWithZone:zone] init];
[nodeCopy setSize:[self size]];
[nodeCopy setSubnodes:[[self subnodes] copyWithZone:zone]];
return nodeCopy;
}但客户端会终止,并出现以下异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '[NOTE: this exception originated in the server.]
Cannot create BOOL from object <Node: 0x10018f640> of class NSDistantObject'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff81f687b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff823a80f3 objc_exception_throw + 45
2 Foundation 0x00007fff8831e0c3 -[NSConnection sendInvocation:internal:] + 4304
3 CoreFoundation 0x00007fff81f3a98c ___forwarding___ + 860
4 CoreFoundation 0x00007fff81f36a68 _CF_forwarding_prep_0 + 232
5 MyProgram 0x00000001000015d5 main + 260
6 MyProgram 0x0000000100000fa8 start + 52
7 ??? 0x0000000000000002 0x0 + 2
)
terminate called after throwing an instance of 'NSException'你知道这里出了什么问题吗?显然,某个地方需要BOOL变量,但Node不包含任何变量,也没有使用任何方法来期望或返回BOOL。
发布于 2011-01-17 22:59:22
有两种可能的选择:
整个树的
对于性能和代码可读性,我更喜欢共享内存。参考起点是shmget(2) manual page。
https://stackoverflow.com/questions/4714254
复制相似问题