Hi I’m working on an app which creates an NSArray of NSNumbers based on a set of upper and lower bounds set by the user. There will be a min of 5000 randomly created numbers within these bounds…
I’m trying to work out the best way to get the frequency of each randomly generated NSNumber that appears in the array.
Currently I’m thinking I need to parse it through some (?) and set up a NSDictionary with the key as the number and the frequency it appears. However it’s trying to actually do this efficiently where my mind is freezing up…
The easiest way would be to use an NSCountedSet. Just use initWithArray to create a set from your array, and it will unique the items (each value will only go in once), but will give you a count of the number of times a particular object was encountered. Here is an example: