Database Reference
In-Depth Information
Remember how earlier in the chapter, you defined your fetch request in the data
model? It turns out that if you use that technique, the fetch request becomes
immutable. You can't change its predicate at runtime, or else this will happen. If
you want to set a fetch request in advance, you have to do it in the data model
editor.
Still in
ViewController.swift
, go back to
viewDidLoad
and make the following
change:
override
func
viewDidLoad() {
super
.
viewDidLoad
()
// fetchRequest =
// coreDataStack.model.fetchRequestTemplateForName("FetchRequest")
fetchRequest
=
NSFetchRequest
(entityName:
"Venue"
)
fetchAndReload
()
}
Comment out the line that retrieves the fetch request from the template in the
managed object model. Instead, create an instance of
NSFetchRequest
directly.
Build and run the sample app one more time. Go to the Filter screen, tap the
second price category cell (
$$
) and then tap
Search
in the top-right corner. This is
the result: