Right now I’m taking my NSDictionary and running a loop of all values to find the low, high, and calculate average.
Since I’m new to IOS I wanted to ask if there is a better way to do this. Is there? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The exact answer to this question depends on what type of objects are in your NSDictionary. The answer in general is that you can probably use Key-Value Coding operators to do what you want. Here is an example:
This is probably no more efficient than enumerating things yourself, but it is more concise.
If the contents of your NSDictionary are objects of a custom class that have an NSNumber as a property, you can still use this method by placing the property name after the
@avg, e.g.@avg.myProperty. Note that thesevalueForKeyPathmethods return NSNumbers.