简体   繁体   中英

How to reference a type in a module that has a type with the same name as the module it is in?

I am trying to reference a type inside a framework that has a type whose name is the same as the framework. Easier to explain in code:

In Framework Something

public struct A { ... }
public class Something { ... }

In Framework OtherFramework

public struct A { ... }

Then on the main project I import both modules:

import Something
import OtherFramework

let myA = A() // 'A' is ambiguous for type lookup in this context

And if I do

import Something
import OtherFramework

let myA = Something.A() // 'A' is not a member type of 'Something'

Is there any way to reference A in Something other than changing the framework?

一种可能的方法是不导入整个模块,只导入您需要的特定类型,例如导入类Something in module Something

import class Something.Something

One solution I found is to create a separate .swift file with this:

import Something
typealias SomethingA = A

And then

import Something
import OtherFramework

let myA = SomethingA()

Have you tried

import Something
import OtherFramework

let myA = Something.Something.A()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM