I have a framework. this is the entire thing:
import Foundation
public let BKNoteChangeAdd : String = "BKNoteChangeAdd"
public let BKNoteChangeRemove : String = "BKNoteChangeRemove"
public let BKNoteChangeSet : String = "BKNOteChangeSet"
public protocol BKNotifier{
func registerForNotes(observer: NSObject)
func unregisterForNotes(observer: NSObject)
func updateRegisteredObservers(_ key: String, change: [String : [Any]], objectPath : [BKNotifier])
}
public protocol BKObserver{
func objectChanged(_ objectPath: [BKNotifier] , key: String, change : [String : [Any]])
}it defines 2 protocols.
this framework is built ina different project than the one I am currently working on.
I would have rather installed it on the machine and just imported it into my project that way, but there's nothing detailing how to do that, and it's clearly not automatic. So instead, I am adding it to my project.
I drag the product from XCode's file list to my current project.
(i Have now done this dozens of times)
I discovered that a change was necessary in order to get my protocol to work in the new context... registerForNotes and unregisterForNotes' observer property was AnyObject. It is required to be NSObject to work inside of a struct... I can't explain it, I didn't set the limitations... AnyClass doesn't work, But NSObject does. I am not put out by that at all. But, when I made the change in my framework, and recompiled, and deleted and re-dragged, and imported the framework into my new framework...
I get error messages that my class does not conform to BKNotifier, here's those two methods:
public mutating func registerForNotes(observer: NSObject) {
if observer is BKObserver && regObjs.contains(observer) == false{
regObjs.append(observer)
}
}
public mutating func unregisterForNotes(observer: NSObject) {
if let anIndex = self.regObjs.firstIndex(of: observer){
self.regObjs.remove(at: anIndex)
}
}and if I let the editor make stubs for conforming to BKNotifier I get this:
public func registerForNotes(observer: AnyObject) {
<#code#>
}
public func unregisterForNotes(observer: AnyObject) {
<#code#>
}I tried AnyObject precisely 1 time. yet I can completely remove all references to the framework, remove all framework related code, clean the BKNote framework's compile, and recompile, re-do everything... from scratch... and it still throws this error.
what else can I try?
and... same bug.
correction: new bug.
the framework did not specify : mutating which is required in a structure's function that will change values in the structure.
don't know how that's going to play in classes. Not looking forward to finding out.
once I added the mutating keyword to the two functions, recompiled replaced the binary re-linked... everything went smoothly.
So there you have it: XCode can sometimes destroy your project, and you won't know why, how, or when. Best to keep on your toes.