下面的错误是由'let managedObjectContext = getMainContext()
'代码行导致的,导致这种情况,因为我无法理解为什么我无法使用该函数而没有问题
在'RoutineController'类型上使用实例成员'getMainContext';你的意思是使用'RoutineController'类型的值吗?
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
}
答案 0 :(得分:1)
我相信如果您添加self.
,它会解决您的问题。
let managedObjectContext = self.getMainContext()
使用计算变量时,您需要指定self来访问正确的方法。
希望这有帮助