Use of instance member '' on type '''; did you mean to use a value of '' type instead?
12,325
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
Author by
infernouk
Updated on June 04, 2022Comments
-
infernouk almost 2 years
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 issueUse 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 }