Re: CoreData Question
Re: CoreData Question
- Subject: Re: CoreData Question
- From: William Squires <email@hidden>
- Date: Tue, 03 Jun 2014 13:10:48 -0500
On Jun 2, 2014, at 8:38 PM, Laurent Daudelin <email@hidden> 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@hidden
> AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/
> Logiciels Nemesys Software
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden