问题
Consider:
- A Swift framework called
FrameworkA
that defines the typeThing
. - A Swift framework called
FrameworkB
that also defines the typeThing
and the typeFrameworkA
. - An app that imports both frameworks in the same Swift file.
How do I reference FrameworkA.Thing
in said file? The following line fails with Thing is not a member of FrameworkA
.
let t : FrameworkA.Thing? = nil
回答1:
This appears to be a Swift bug. As a workaround, you can create a new Swift file in the app that imports only FrameworkA
and defines a typealias
for Thing
:
import FrameworkA
typealias ThingA = Thing
Then in the file that needs to import both frameworks, you use ThingA
instead of FrameworkA.Thing
.
来源:https://stackoverflow.com/questions/26774101/swift-namespace-conflict