Database Reference
In-Depth Information
fetchRequest.
predicate
=
expensiveVenuePredicate
var
error:
NSError
?
let
count =
coreDataStack
.
context
.
countForFetchRequest
(fetchRequest,
error: &error)
if
count ==
NSNotFound
{
println
(
"Could not fetch
\(error)
,
\(error!.
userInfo
)
"
)
}
thirdPriceCategoryLabel
.
text
=
"
\(count)
bubble tea places"
}
Like in the previous two scenarios, here you create a fetch request for retrieving
Venue
objects. Then you set the predicate that you defined as a lazy property
moments earlier,
expensiveVenuePredicate
.
The difference between this scenario and the last two is that here, you don't set the
result type to
NSCountResultType
. Rather than the usual
executeFetchRequest()
, you
use
NSManagedObjectContext
's method
countForFetchRequest()
instead.
The return value for
countForFetchRequest()
is an integer that you can use directly
to populate the third price category label.
Finally, modify
viewDidLoad
to invoke the method you just defined:
override
func
viewDidLoad() {
super
.
viewDidLoad
()
populateCheapVenueCountLabel
()
populateModerateVenueCountLabel
()
//add the line below
populateExpensiveVenueCountLabel
()
}
Build and run to see if your latest changes took effect. The filter/sort screen should
look like this: