On Jun 2, 2014, at 8:38 PM, Laurent Daudelin <[email protected]> wrote:

> I have what I think is a simple CoreData question.
> 
> Suppose I have an Employee table and a City table, a little bit like the 
> CoreData documentation. Each employee resides in a city.
> 
> Now, multiple employees can reside in the same city. Suppose I fetch a 
> certain number of employees, how do I find how many cities this group of 
> employees reside in? 
> 
As a general answer:

1) Fetch all the employees using whatever criteria you need.
2) Iterate over all the employee entity objects
  a) for each entity object, check the dictionary to see if it has the entity 
name as a key in it. If so, do steps (b) and (c)
  b) for each entity object, store the entity name as the key in an 
NSMutableDictionary
  c) for each entity object, fetch it's related city entity, and store the city 
name as the value for that key.
3) Grab the list of all values stored in your NSMutableDictionary by pulling it 
into an NSArray using -(NSArray *)allValues; on the dictionary.
4) [<array> count] then gives you the number of cities (not necessarily unique) 
that are associated with the pulled employee entities.

HTH!

> -Laurent.
> -- 
> Laurent Daudelin                                                      
> [email protected]
> AIM/iChat/Skype:LaurentDaudelin                               
> http://www.nemesys-soft.com/
> Logiciels Nemesys Software
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/wsquires%40satx.rr.com
> 
> This email sent to [email protected]


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to