无法覆盖NSFetchedResultsControllerDelegate中的controllerDidChangeContent

时间:2017-11-19 00:58:11

标签: ios swift core-data nsfetchedresultscontroller swift4

问候Stack的公民, 当试图覆盖" controllerDidChangeContent"我得到"方法不会覆盖其超类"中的任何方法。存根由自动完成处理程序生成,它似乎符合Apple Documentation的要求。代码如下:

import UIKit
import CoreData

  class ViewController: UITableViewController, NSFetchedResultsControllerDelegate{
  var frc: NSFetchedResultsController<People>?

    override func viewDidLoad() {
       super.viewDidLoad()

       let appdelegate = UIApplication.shared.delegate as! AppDelegate
       let context = appdelegate.persistentContainer.viewContext

       let request: NSFetchRequest<People> = People.fetchRequest()
       request.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true )]

       frc = NSFetchedResultsController(fetchRequest: request,
                                     managedObjectContext: context,
                                     sectionNameKeyPath: nil,
                                     cacheName: nil)

       }

   override func controllerDidChangeContent(_ controller:  NSFetchedResultsController<NSFetchRequestResult>) {
       print(controller.description)
   }
}

错误由覆盖代码产生。我把print()放在那里作为填充物。 THX

1 个答案:

答案 0 :(得分:0)

删除override

您正在实施协议,而不是覆盖。