Swift名称空间冲突 [英] Swift namespace conflict
本文介绍了Swift名称空间冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑:
- 一个名为
FrameworkA
的Swift框架,它定义了类型Thing
. - 一个名为
FrameworkB
的Swift框架,该框架还定义了Thing
类型和FrameworkA
类型. - 一个将两个框架都导入到同一个Swift文件中的应用.
- 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.
如何在所述文件中引用FrameworkA.Thing
?以下行失败,并显示Thing is not a member of FrameworkA
.
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
推荐答案
这似乎是一个Swift错误.解决方法是,您可以在应用程序中创建一个新的Swift文件,该文件仅导入FrameworkA
并为Thing
定义typealias
:
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
然后在需要导入两个框架的文件中,使用ThingA
而不是FrameworkA.Thing
.
Then in the file that needs to import both frameworks, you use ThingA
instead of FrameworkA.Thing
.
这篇关于Swift名称空间冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文