我有兩個包:FirstModuleand 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 ' '并指向兩個匯入的模塊。并非我的應用程式中的所有課程都使用FirstModule,AnotherModule但他們只需要func ()
如何避免func ()從FirstModule課堂AnotherModule匯入Whatever?
uj5u.com熱心網友回復:
一種可能的方法是從其中一個模塊中顯式匯入您正在使用的所有內容。
您可以顯式匯入型別別名、結構、類、列舉、協議、全域lets、vars 和函式。
例子:
import typealias FirstModule.SomeTypeAlias
import struct FirstModule.SomeStruct
import class FirstModule.SomeClass
import enum FirstModule.SomeEnum
import protocol FirstModule.SomeProtocol
import let FirstModule.someGlobalConstant
import var FirstModule.someGlobalVar
import func FirstModule.someGlobalFunction
import AnotherModule
// now you will use the CGPoint. from AnotherModule
請注意,您不能顯式匯入擴展或運算子。如果您需要CGPoint. 來自.FirstModuleimport FirstModule
(不用說,您應該替換FirstModule為使用較少成員的模塊)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533046.html
標籤:迅速快速编译器
