2

Error below is caused by the 'let managedObjectContext = getMainContext()' line of code, whats causing this as I couldnt see why i wouldnt be able to use the function without issue

Use of instance member 'getMainContext' on type 'RoutineController'; did you mean to use a value of type 'RoutineController' instead?

    fileprivate lazy var fetchedExercisesTodayController: NSFetchedResultsController<UserExercise> = {

    let managedObjectContext = getMainContext()
    let userExercise = UserExercise(context: managedObjectContext)

    let fetchRequest: NSFetchRequest<UserExercise> = UserExercise.fetchRequest()
    fetchRequest.predicate = NSPredicate(format: "(usersroutine == %@)", self.routineName)
    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true)] //this isnt really needed

    let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.persistentContainer.viewContext, sectionNameKeyPath: nil, cacheName: nil)
    fetchedResultsController.delegate = self
    return fetchedResultsController
}()

func getMainContext() -> NSManagedObjectContext {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    return appDelegate.persistentContainer.viewContext
}
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
infernouk
  • 1,137
  • 4
  • 13
  • 21

1 Answers1

2

I believe if you add self. it will fix your problem.

let managedObjectContext = self.getMainContext()

When using a computed variable you need to specify self to access the correct method.

Hope this helps

Steve
  • 921
  • 1
  • 7
  • 18