override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)-> UITableViewCell{ let note = fetchedResultsController?.object(at: indexPath) as! Note let cell = tableView.dequeueReusableCell(withIdentifier: "Note", for: indexPath) cell.textLabel?.text = note.text return cell }
override func prepare(for segue: UIStoryboardSeque, sender: Any?){ if segue.identifier! == "displayNote"{ if let notesVC = segue.destination as? NotesViewController { let fr = NSFetchRequest<NSFetchRequestResult>(entityName: "Note") fr.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending:false),NSSortDescriptor(key: "text", ascending: true)] let indexPath = tableView.indexPathForSelectedRow! let notebook = fetchedResultsController?.object(at: indexPath) let pred = NSPredicate(format: "notebook = %@", argumentArray: [notebook!]) fr.predicate = pred let fc = NSFetchedResultsController(fetchRequest: fr, managedObjectContext:fetchedResultsController!.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil) notesVC.fetchedResultsController = fc } } }