Database Reference
In-Depth Information
As expected, there are only two venues in this category. Test the first ($) and third
($$$) price category filters as well and make sure the filtered list contains the
correct number of venues for each.
Let's practice writing a few more predicates for the remaining filters. The process is
similar to what you've done already, so this time you'll do it with less explanation.
Switch to FilterViewController.swift once more and add these three lazy
properties to the top of the class:
lazy var offeringDealPredicate: NSPredicate = {
var pr = NSPredicate (format: "specialCount > 0" )
return pr
}()
lazy var walkingDistancePredicate: NSPredicate = {
var pr = NSPredicate (format: "location.distance < 500" )
return pr
}()
lazy var hasUserTipsPredicate: NSPredicate = {
var pr = NSPredicate (format: "stats.tipCount > 0" )
return pr
}()
The first predicate specifies venues that are currently offering one or more deals,
the second predicate specifies venues that are less than 500 meters away from
your current location and the third predicate specifies venues that have at least one
user tip.
Note: So far in the topic, you've written predicates with a single condition.
You can write predicates that check two conditions instead of one by using
compound predicate operators such as AND , OR and NOT .
Alternatively, you can string two simple predicates into one compound
predicate by using the class NSCompoundPredicate .
NSPredicate isn't technically part of Core Data (it's part of Foundation) so this
book won't cover it in depth, but you can seriously improve your Core Data
chops by learning the ins and outs of this nifty class. For more information,
make sure to check out Apple's Predicate Programming Guide:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Pr
edicates/predicates.html
Search WWH ::




Custom Search