I would like to ask how could I count object type inside array. For example
this is my dataclass
+ (id)LocationWithID:(NSString *)UniqueID name:(NSString *)name address:(NSString *)address latitude:(float )latitude longitude:(float )longitude locationtype:(NSString *)locationtype country:(NSString *)country distance:(float )distance;
and this is my array
[array addObject:[dataclass LocationWithID:UniqueID name:name address:address latitude:latitude longitude:longitude locationtype:locationtype country:country distance:distance]];
and i would like to count how many country in this object. Normally we use
[array count];
but this will count all the object in the array. Now in my case i want to count non-repeated object for example i got an array contain 3 United kingdom, 5 USA, 7 Japan, 3 China and the result i want is country type = 4.
I would like to create several section for Table View according to the country type. Anyone?
You can use a dictionary to put objects with the same country in a separate array:
Now, not only you can get the number of different countries like this:
But also, it is easy to populate each section of your table view with locations from the corresponding country.
You can retrieve all the locations for a specific country that has the name
countryName, like this:You can also have the list of all the countries like this: