Click here to Skip to main content
15,885,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

The code work good when I was using Xcode 7.3 with iOS 9 but when I migrated to Xcode 8 using swift 3 ,the code below show me that runtime error.still finding a solution for it

class TableViewController: UITableViewController,NSFetchedResultsControllerDelegate,UISearchResultsUpdating {

var fetchResultController :NSFetchedResultsController<Restaurant>!

var searchController : UISearchController!

var searchResults :[Restaurant] = []

override func viewDidLoad() {
super.viewDidLoad()



let fetchRequest : NSFetchRequest<NSFetchRequestResult> = Restaurant.fetchRequest()
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]




if let managedObjectContext = (UIApplication.shared.delegate as? AppDelegate)?.managedObjectContext{



fetchResultController = NSFetchedResultsController(fetchRequest: fetchRequest as! NSFetchRequest<Restaurant>, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)

fetchResultController.delegate = self

do{
try fetchResultController.performFetch()
restaurants = fetchResultController.fetchedObjects!
}
catch{
print(error)
}

}
}

What I have tried:

I have tried so many resources such as official documentation , developer forums as well as browse the web for it but didn't find anything
Posted
Updated 10-Apr-17 22:11pm

1 solution

It feel like context is not properly set .

Please try
Objective-C
let ad = UIApplication.shared.delegate as! AppDelegate
let context = ad.persistenceContainer.viewContext
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900