Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

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?

like image 361
Alejandro Avatar asked May 02 '16 21:05

Alejandro


2 Answers

One possible way is not to import the whole module, import only the specific types you need, e.g. to import a class Something in module Something:

import class Something.Something
like image 65
Sulthan Avatar answered Oct 17 '22 19:10

Sulthan


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()
like image 21
Alejandro Avatar answered Oct 17 '22 20:10

Alejandro