Thursday, 12 September 2013

Cannot perform operation because childrenKeyPath is nil

Cannot perform operation because childrenKeyPath is nil

Why do I get this crash error when I try to insert a child into my
NSTreeController?
NSTreeController *tree = [NSTreeController new];
NSTreeNode *node1 = [NSTreeNode treeNodeWithRepresentedObject:@{ @"type":
@"shirt" }];
// The below method causes mysterious crash
[tree insertObject:node1 atArrangedObjectIndexPath:[NSIndexPath
indexPathWithIndex:0]];
and Xcode says:
*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '<NSTreeController:
0x1005c4620>[object class: NSMutableDictionary] Cannot perform operation
because childrenKeyPath is nil'
***
Why is causing this error? What is childrenKeyPath and why do I need it
(I'm not using interface builder)?

1 comment: