在 Framework1 我有以下代码:
public protocol SomeProtocol{
func doSomething()
}
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
在将 Framework1 作为 Cocoa pod 导入的 Framework2 中,我像这样添加对 SomeProtocol 的一致性
extension UIButton : SomeProtocol{}
Framework1 构建成功,但是,我在构建 Framework2 时收到以下 Apple Mach-O 链接器错误:
架构 x86_64 的未定义符号:“(Framework1 中的扩展):Framework1.SomeProtocol.doSomething () -> ()”,引用自:Framework1.SomeProtocol.doSomething () -> () 的协议见证,符合 __ObjC.UIButton : Framework1 SomeFile.old 中 Framework2 中的 .SomeProtocol:未找到体系结构 x86_64 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
如果我将 UIButton 的协议一致性移动到 Framework1 文件中,如下所示:
public protocol SomeProtocol{
func doSomething()
}
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
extension UIButton : SomeProtocol{}
Framework1 将成功构建。这对我不起作用,因为我需要在 Framework2 而不是 Framework1 中建立 UIButton 与 SomeProtocol 的一致性。
我目前的解决方案只是删除
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
从 Framework1 并在 Framework2 的 UIButton 扩展中实现它,如下所示:
extension UIButton : SomeProtocol{
public func doSomething(){}
}
然而,这不是一个好的解决方案,因为我希望能够在任何使用 Framework1 的框架之间共享 UIButton 的 doSomething 实现。任何帮助,将不胜感激!