In Framework1 I have the following code:
public protocol SomeProtocol{
func doSomething()
}
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
In Framework2, which imports Framework1 as a Cocoa pod, I add conformance to SomeProtocol like this
extension UIButton : SomeProtocol{}
Framework1 builds successfully, however, I receive the following Apple Mach-O Linker Error when building Framework2:
Undefined symbols for architecture x86_64: "(extension in Framework1): Framework1.SomeProtocol.doSomething () -> ()", referenced from: protocol witness for Framework1.SomeProtocol.doSomething () -> () in conformance __ObjC.UIButton : Framework1.SomeProtocol in Framework2 in SomeFile.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I move the protocol conformance of UIButton into Framework1 file as such:
public protocol SomeProtocol{
func doSomething()
}
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
extension UIButton : SomeProtocol{}
Framework1 will successfully build. This does not work for me though because I need to establish UIButton's conformance to SomeProtocol in Framework2 and not Framework1.
My current solution is simply to remove
extension SomeProtocol where Self : UIButton{
public func doSomething(){}
}
from Framework1 and implement it in the UIButton extension in Framework2 like this:
extension UIButton : SomeProtocol{
public func doSomething(){}
}
This, however, is not a good solution because I would like to be able to have this implementation of doSomething for a UIButton shared between any framework consuming Framework1. Any help would be appreciated!