Modern iOS app development part 2

Modern iOS App Development

All .net developers know that LINQ can be used to conveniently extract and process data from arrays, enumerable classes, XML documents, relational databases, and third-party data sources. These concepts are adopted by other programming languages such as Java, Javascript, Ruby etc.


var cityWiseSalary = from comp in ListCompany 
                     select new { 
                            Emp = (from emp in comp.ListEmp 
                            group emp by emp.Address.City into CityWiseEmp
                            select new {
                                   State = CityWiseEmp.Key,
                                   TotalSalary = CityWiseEmp.Sum(emp => emp.salary) 
Covid 19
COVID-19: Digital Insights For Enterprise Action

Access Perficient’s latest insights into how you can leverage digital technologies to not only respond to the pandemic, but drive your operations forward and deliver experiences your customers need.

Get Informed

There is no reason that we can’t port it to Objective-C. By using LinqToObjectiveC, we could write Objective-C code like:

NSArray* input = @[@"Frank", @"Jim", @"Bob"];

NSDictionary* dictionary = [input linq_toDictionaryWithKeySelector:^id(id item) {
    return [item substringToIndex:1];
} valueSelector:^id(id item) {
    return [item lowercaseString];

// result:
// (
//    F = frank;
//    J = jim;
//    B = bob;
// )

Comparing to the old school KVC way:

NSArray *payees = [arrayOfTransactionsArrays valueForKeyPath:@"@distinctUnionOfArrays.payee"];

The API is not so intuitive, and not composable, is it?

About the Author

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up