简体   繁体   中英

Core Data: Find the property of NSEntity Objects in NSMutableSet

How can I efficiently find the attributes of an NSEntity object in a set ?

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?

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.

Models:

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

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

From a first time 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:

    iPhone - getting unique values from NSArray object

    But I have no reason to think that is more efficient .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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