Paul wrote an excellent piece asking Apple to provide code examples for all their APIs. This would have helped a great deal.
Reimagining Apple's Documentation
Here's the solution I found.
First, you can create predicates in the core data modeler using pick lists. Very easy to say you want all states that begin with "New". Or all sodas that contain "Cola". But these are static fetch requests.
What if you'd like to insert a varible?
In this case, you need to select the Custom Predicate in the data modeler. Then you have to craft a predicate that conforms to NSPredicate syntax AND holds your variables.
Here's an example:
name BEGINSWITH $ARTISTS_NAME
Please note the variable begins with a $.
Now that this template is stored in your xcdatamodeld file in your project, you can extract the fetch request template with code, and substitute variables harvested from your awesome SwiftUI interface! Sweet!
let fetchTemplate = "byArtist" // this is the name in the xcdatamodeld file.
let subs = ["ARTISTS_NAME" : "Taylor Swift"] // Paul's favorite example
let fetchRequest = mom.fetchRequestFromTemplate(withName: fetchTemplate, substitutionVariables: subs)
print ("Predicate is: \(fetchRequest.predicate)")
This will return a proper fetchRequest with the predicate: name BEGINSWITH "Taylor Swift"
Please Note!
You must include the $ before the variable name IN THE xcdatamodeld file.
BUT you do NOT include the $ in the substitution dictionary. Not sure why. I hope a core data boffin might explain this? Seems a relic leftover from printf days.