Swift名称空间冲突 [英] Swift namespace conflict

查看:88
本文介绍了Swift名称空间冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑:

  • 一个名为FrameworkA的Swift框架,它定义了类型Thing.
  • 一个名为FrameworkB的Swift框架,该框架还定义了Thing类型和FrameworkA类型.
  • 一个将两个框架都导入到同一个Swift文件中的应用.
  • A Swift framework called FrameworkA that defines the type Thing.
  • A Swift framework called FrameworkB that also defines the type Thing and the type FrameworkA.
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆