0

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.

GangstaGraham
  • 8,865
  • 12
  • 42
  • 60

1 Answers1

2
  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.

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Great answer. Thanks. Maybe I'm focusing on the wrong thing (efficiency) instead of focusing on getting the app done. Appreciate the feedback and will take a look at the KVC example. :) @matt – GangstaGraham Apr 27 '13 at 02:15