模棱两可的使用方法

ambiguous use of method

我的构建成功完成。然后一段时间后弹出此错误:

"Ambiguous use of 'addObjectsDidChangeNotificationObserver(handler:)'"

我不明白为什么会这样,因为addObjectsDidChangeNotificationObserver方法在项目中只声明了一次,而Xcode显示的第二次出现是方法本身的使用。

这是显示错误的代码,Xcode 也显示我是第一个候选人:

public init?(object: Managed, changeHandler: @escaping (ChangeType) -> ()) {
    guard let moc = object.managedObjectContext else { return nil }

    objectHasBeenDeleted = !type(of: object).defaultPredicate.evaluate(with: object)

    token = moc.addObjectsDidChangeNotificationObserver(handler: {
        [unowned self] note in
        guard let changeType = self.changeType(of: object, in: note) else { return }
        self.objectHasBeenDeleted = changeType == .delete
        changeHandler(changeType)
    })
}

addObjectsDidChangeNotificationObserver() 的实施,Xcode 表明我是第二个候选人:

extension NSManagedObjectContext {
    public func addObjectsDidChangeNotificationObserver(handler: @escaping (ObjectsDidChangeNotification) -> ()) -> NSObjectProtocol {
        let nc = NotificationCenter.default
        return nc.addObserver(forName: .NSManagedObjectContextObjectsDidChange, object: self, queue: nil) { note in
            let wrappedNote = ObjectsDidChangeNotification(note: note)
            handler(wrappedNote)
        }
    }
}

好了,问题好像解决了

显然,我搞砸了访问修饰符,但很高兴知道这样的事情会导致模棱两可的错误