iphone - KVC vs fast enumeration -


which of following faster , why?

cgfloat sum = 0; (uiview *v in self.subviews)     sum += v.frame.size.height; 

or

cgfloat sum = [[self.subviews valueforkeypath:@"@sum.frame.size.height"] floatvalue]; 

really, lot of how elegant (or clever) language comes down how avoids loops. for, while; fast enumeration expressions drag. no matter how sugar-coat them, loops block of code simpler describe in natural language.

"get me average salary of of employees in array",

double totalsalary = 0.0; (employee *employee in employees) {   totalsalary += [employee.salary doublevalue]; } double averagesalary = totalsalary / [employees count]; 

versus...

fortunately, key-value coding gives more concise--almost ruby-like--way this:

[employees valueforkeypath:@"@avg.salary"]; 

kvc collection operators allows actions performed on collection using key path notation in valueforkeypath:.

any time see @ in key path, denotes particular aggregate function result can returned or chained, other key path.

fast enumeration faster kvc.

hope helps you.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -