简体   繁体   English

核心数据:在NSMutableSet中查找NSEntity对象的属性

[英]Core Data: Find the property of NSEntity Objects in NSMutableSet

How can I efficiently find the attributes of an NSEntity object in a set ? 如何有效地在集合中查找NSEntity对象的属性?

I have implemented it this way, but it seems to be inefficient. 我已经用这种方式实现了它,但它似乎效率低下。 Is there a faster, easier, more efficient method of finding the attributes of an NSEntity object in a set , than this approach? 与此方法相比,是否有更快,更简单,更有效的方法来查找集合中NSEntity对象的属性

soccerTeamViewController.players = [[NSMutableArray alloc] init];
for (GGPlayer *playa in chelsea.players) {
    [soccerTeamViewController.players addObject:playa.name];
}

^here chelsea is a GGTeam, it has a set of GGPlayers as a property. ^这里chelsea是一个GGTeam,它有一套GGPlayers作为财产。

Models: 楷模:

GGTeam:
@property (nonatomic, retain) NSMutableSet *players;

GGPlayer:
@property (nonatomic, retain) NSString *name;

From a first time iOS-er. 从第一次iOS-er。

  1. Do not optimize prematurely. 不要过早优化。 You have no evidence as to whether what you are doing is inefficient or not. 你没有证据表明你所做的事情是否效率低下。 If there appears to be a slowdown, use Instruments and figure it out. 如果似乎有减速,请使用仪器并弄清楚。 But don't guess, and especially don't guess in advance. 但不要猜测,特别是不要提前猜测。

  2. What you're doing is perfectly standard. 你正在做的是完全标准的。

  3. There is a more elegant way, namely to use KVC, as described here: 有一种更优雅的方式,即使用KVC,如下所述:

    iPhone - getting unique values from NSArray object iPhone - 从NSArray对象获取唯一值

    But I have no reason to think that is more efficient . 但我没有理由认为这更有效率

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM