Database Reference
In-Depth Information
Now that you're acquainted with the count result type, let's quickly implement the
count for the second price category filter.
Add the following lazy property below the first one you added earlier:
lazy var moderateVenuePredicate: NSPredicate = {
var predicate =
NSPredicate (format: "priceInfo.priceCategory == %@" , "$$" )
return predicate
}()
This NSPredicate is almost identical to the cheap venue predicate, except that this
one matches against $$ instead of $.
Similarly, add the following method below populateCheapVenueCountLabel :
func populateModerateVenueCountLabel() {
// $$ fetch request
let fetchRequest = NSFetchRequest (entityName: "Venue" )
fetchRequest. resultType = .CountResultType
fetchRequest. predicate = moderateVenuePredicate
var error: NSError ?
let result =
coreDataStack . context . executeFetchRequest (fetchRequest,
error: &error) as [ NSNumber ]?
if let countArray = result {
let count = countArray[ 0 ]. integerValue
secondPriceCategoryLabel . text =
" \(count) bubble tea places"
} else {
println ( "Could not fetch \(error) , \(error!. userInfo ) " )
}
}
Finally, modify viewDidLoad to invoke your newly defined method:
override func viewDidLoad() {
super . viewDidLoad ()
populateCheapVenueCountLabel ()
Search WWH ::




Custom Search