4
votes

I would like to print Data from CoreData in TableView for an iOS Application in Swift 3.

In the ListTableViewController file I've this code :

    override func viewDidAppear(_ animated: Bool) {
    let appDel: AppDelegate = UIApplication.shared.delegate as! AppDelegate
    let managedObjectContext = appDel.persistentContainer.viewContext
    let contxt :NSManagedObjectContext = appDel.managedObjectContext!

    let freq = NSFetchRequest<NSFetchRequestResult>(entityName:"Location")


    tableView.reloadData()
}

On the let context line, I've a error : "Value of type 'AppDelegate' has no member 'manageObjectContext'"

Have you an idea about my problem ?

Thank's

1
appDel.managedObjectContext! should be simply managedObjectContext!, no? - Sergey Kalinichenko
even without the !, simply let contxt : NSManagedObjectContext = managedObjectContext, since it is not an optional - Mr. Xcoder

1 Answers

6
votes

Error indicating that you don't assign any value into variable name managedObjectContext in Appdeleget. First, you have to define a variable and then assign a ManagedObjectContext object into it. But you can get the ManagedObjectContext object reference by below code as well as.

let managedObjectContext = appDel.persistentContainer.viewContext as! NSManagedObjectContext
let contxt = managedObjectContext