Programmatically retrieving a selected NSArrayController

When I use NSArrayController with instances of NSManagedObject , I got the impression that the following will provide me with my selected object:

 [myArrayController selection] 

However, this gives me an instance of some private NS Proxy class.

When i use:

 [[myArrayController selectedObjects] objectAt: 0] 

... everything is fine and I have an instance of NSManagedObject .

I understand the need for these methods, since you can probably have lists that allow multiple selection. I do not understand why selection does not give me an instance of NSManagedObject .

+7
source share
1 answer

The documentation for the NSObjectController (which NSArrayController inherits) says that this method returns a proxy object.

You can use any KVC methods for the proxy object, but if you need any class functionality, you will have to use the second method in your example above. As you stated, this is a return of a valid object in case of absence or multiple choice.

+8
source

All Articles