The master branch has a working project that (at the moment) is pulling in all the opinion articles.
NB: As of now it does not do uniquing so multiple runs of the app will double up records. I'll get back to you on this one. (Pulling hair out.)
-
Complete the Article object in the data modeler without including any nested structures. I.e. no "*_facet" fields and no "multimedia". We'll do that next time.
-
Add a Search bar to the TableView and implement its delegate methods to accept input from it. Search Bar Delegate.
-
Alter the
initializeFetchedResultsController
function so that it can be re-reun with new parameters. You want to pass in a predicate and a sort. This will be done via the search bar input from the user.Oohinput from the user is bad. This hearkens back to the pre Battleship era where we processed input from the user on the command line. You should:-
Get the string from the search bar.
-
Parse out a predicate string and a sort, probably using
components(separatedBy: String)
. E.g. userp=abstract/environment s=title
After plucking out "abstract", "environment" and "title" you can update these lines accordingly:
let sort = NSSortDescriptor(key: "title", ascending: true) . . . // current line // let predicate = NSPredicate(format: "title < %@", "M") let predicate = NSPredicate(format: "@K contains[c] %@", field, search)
Note, in this example for the predicate I'm making both the field and its value controllable by the user. It might be easier to start with just the value and then add the field.
let predicate = NSPredicate(format: "abstract contains[c] %@", search)
-
-
Add sections as per the
sectionNameKeyPath
parameter of:
NSFetchedResultsController(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil)
If you're feeling ambitious, you can also accept input from the user for this sectonNameKeyPath, either as another part of the search bar input or from more elaborate input (e.g. a settings VC with a picker).