01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Summary<br />

227<br />

The core of the logic occurs in the alertView:clickedButtonAtIndex: method. This<br />

method is invoked when the user taps the right-hand button on the navigation bar<br />

and selects a desired filter condition. The method first creates an NSPredicate<br />

instance detailing which properties should still be displayed in the UITableView.<br />

This predicate then filters the array of all rental properties (allProperties) using<br />

the predicate to come up with a new array (filteredProperties) consisting of the<br />

subset of rental properties that meet the specified conditions. The UITableView is<br />

then requested to reload using this second array to display the filtered set of rental<br />

properties to the user.<br />

11.5 Summary<br />

KVC- and NSPredicate-based logic is a powerful way to query, filter, analyze, and<br />

access data from an in-memory object-based data model. And this is just the tip of the<br />

iceberg of KVC’s true power.<br />

The real power of KVC begins to shine when you realize the level of abstraction it can<br />

provide. When we discussed key-path operators such as @min, @max, and @distinct-<br />

UnionOfObjects, you may have noticed that you expressed, in a simple string format,<br />

what operation was required, then left it up to the framework to determine how to<br />

iterate over the data model and any memory management issues or temporary data<br />

structures required to produce the results.<br />

In chapter 12 you discover that all the concepts discussed in this chapter are transferrable<br />

for use with Core Data–based object models. Although the programming<br />

model is equivalent and familiar, behind the scenes, the implementation couldn’t be<br />

more different. In the case of Core Data, KVC converts key paths and NSPredicatebased<br />

filter expressions into Structured Query Language (SQL) queries that are executed<br />

at the database level.<br />

As a programmer, you for the most part don’t care. You worry about the creation of<br />

the required filter conditions and leave it up to the framework to determine how best<br />

to implement the required logic.<br />

Next up in chapter 12, you’ll learn all about Core Data and how it can help you in<br />

the creation of robust iOS applications.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!