views:

114

answers:

0

I have an entity called Person and it has a relationship called participatingGames, to another entity called GameParticipant.

I (apparently) can retrieve the number of matches in the GameParticipant entity using this simple code in the Person object I created from the entity in the model:

[self.participatingGames count];

However, I'd just like to retrieve the number of Person records and one might guess the syntax for this is just as simple.

I have lots of books including those by Jeff LaMarche, but those sources and what I find around here make me wonder if I need to set up a fetchedResultsController just to know the count of some entity.

My background is in SQL, so of course it seems odd that what would take 15 seconds to code in any other environment seems like such a well-guarded secret in Core Data.

I'm using iPhone SDK 3.1.4 under OSX 10.5.8

Suggestions?

Edit: maybe [self personCount] is the answer, since it compiles and runs. No, that cannot be it. Just noticed it's a circular reference.

Edit: on another thread on stackoverflow, I encountered what appears to be confirmation that there is no single-line syntax for getting counts of table-records/object-instances. Instead, you must go through all the steps to create a fetch request, but instead of executing it, you then do this:

  • (NSUInteger)countForFetchRequest:(NSFetchRequest )request error:(NSError *)error;

The API describes the use of this, of course, but it doesn't tell us there is no other reasonable way to consider. I guess we're supposed to assume that this is the only way (short of actually returning objects/records and counting them.)