开发者

How to get an entity out of a NSEntityDescription

开发者 https://www.devze.com 2023-03-26 07:27 出处:网络
I have a NSTreeController (treeController) and a CoreData database. I want the entity behind the selected object of my NSTreeController.

I have a NSTreeController (treeController) and a CoreData database. I want the entity behind the selected object of my NSTreeController.

I use this to get the 开发者_开发知识库correct NSEntityDescription:

[[[[treeController selectedObjects] objectAtIndex:0] representedObject] entity]

Now I have my testEntity and I want to assign the entity object described by the NSEntityDescription I get with the code above.

MyEntityClass *testEntity;
testEntity = ???

I can't find a method. Is there another way to get the entityObject behind the selected object of the NSTreeController?

Thx!


Usually when you're using an NSTreeController to manage an NSOutlineView, the ‑selectedObjects method of NSTreeController should return an array of NSManagedObject instances.

You can query those instances for their entities using the -entity method of NSManagedObject.

However, the fact that you're called -representedObject (not an NSManagedObject method) means that your tree controller is handling some other sort of object. What is it? How is your tree controller configured? What do you get if you log the output of [[treeController selectedObjects] objectAtIndex:0]?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号