我有两个包:FirstModule
和AnotherModule
,每个包都定义了
extension CGPoint {
public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
CGPoint(x: lhs.x + rhs.x, y: lhs.y+rhs.y)
}
}
也在我定义的主应用程序中
extension CGPoint {
#if !canImport(FirstModule) && !canImport(AnotherModule)
public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
}
...
#endif
}
和另一个文件中的某个类:
#import FirstModule
#import AnotherModule
class Whatever() {
///Uses CGPoint + CGPoint
}
不幸的是,编译器在两个导入的模块上抛出错误:Ambiguous use of operator '+'
AND.
我的应用程序中并不是所有的类都使用FirstModule
和AnotherModule
,但它们只需要func + ()
如何避免从FirstModule
进口func + ()
,Whatever
班进口AnotherModule
?