1

I'm totally baffled why this is not working. I'm trying to insert a new NSTreeNode into a mutable array of child nodes. Here's the code:

NSTreeNode *newNode = [[NSTreeNode alloc] init];
NSMutableArray *children = [anExistingParentTreeNode mutableChildNodes];
[children addObject:newNode];

Upon execution I get all sorts of errors:

  • -[NSCFSet initWithObjects:count:]: attempt to insert nil object at objects[0]
  • -[NSTreeNode _tearDownObserving]: unrecognized selector sent to instance 0x2000bff40
  • Serious application error. Exception was caught during Core Data change processing: -[NSTreeNode _tearDownObserving]: unrecognized selector sent to instance 0x2000bff40 with userInfo (null)

The errors seem to be dealing with KVO stuff. Has anybody encountered errors like these using mutableChildNodes? Any help is greatly appreciated.

Note: The underlying NSTreeController IS bound to core data via managed object context.

Gobot
  • 2,464
  • 1
  • 21
  • 26
  • So after digging around a bit more I am aware that NSTreeController and NSTreeNode have many issues with proxies. So I'm thinking that mutableChildNodes gives me an array of proxies because when adding the new node to the array I get the same amount of: `-[NSTreeNode _tearDownObserving]: unrecognized selector sent to instance 0x2000957a0` as I have nodes in the tree. I traced the class and it states that it is NSTreeControllerTreeNode. So it's a mystery to me. – Gobot Nov 30 '11 at 15:22
  • After more digging, NSTreeNode's mutableChildNodes method returns a mutable array of NSTreeControllerTreeNode, which seems to be a an undocumented and private subclass of NSTreeNode. I decompiled the appkit to try to get any info on this class. I saw that NSTreeControllerTreeNode has a method `-(id)[NSTreeControllerTreeNode initWithRepresentedObject:treeController:] `. – Gobot Nov 30 '11 at 16:40
  • I forward declared `class@ NSTreeControllerTreeNode` and tried out the above init method, AND IT WORKED! Though, because it's a private class (no header file exists?), I'm a bit hesitant to use it, and I'm not sure what side effects might occur by using this class directly. Does anybody have bad experiences using undocumented classes? I assume these classes could have the potential to be drastically changed in future versions. Also does anybody know where to get any documentation on this class? – Gobot Nov 30 '11 at 16:41

2 Answers2

1

Could it be that you have not initialized the newNodeobject correctly?

The only init method defined for the class is:

- (id)initWithRepresentedObject:(id)modelObject

When you use init, you just use the default implementation inherited from NSObject.

Normally, a class has one or more designated initializers, but in the case of NSTreeNode, I can't see that it is specified in the docs. However, since there is only one initializer defined for the class, and no setter methods to set the represented object at a later stage, I'd conclude that initWithRepresentedObject: is the designated initializer of the class.

About initializers: http://developer.apple.com/library/ios/#documentation/general/conceptual/DevPedia-CocoaCore/MultipleInitializers.html

Monolo
  • 18,205
  • 17
  • 69
  • 103
  • 1
    Thanks for the response, but I tried all NSTreeNode initializers, and according to a bunch of NSLog statements the object is alive and healthy. It's when I try to actually add it to the mutable array, that's when the issues occur. – Gobot Nov 30 '11 at 15:11
-2

Refer to my last comment on the original question.

Gobot
  • 2,464
  • 1
  • 21
  • 26