swiftnamespaces

Swift namespace intersections


I have import name equal to inner class name. How I can manage it in code?

import AAA


extension Integrations {
    class AAA {
        class func setup(id: String) {
            AAA.instance.setExternalUserId(id) // here I need take AAA from import
        }
    }
}

On the line AAA.instance.setExternalUserId(id), I need to take AAA from the relevant module. but now I receive error

Type 'Integrations.AAA' has no member 'instance'

P.S. I understand that the easiest solution would be to rename my class, but I prefer to keep the names consistent.


Solution

  • You could try using a typealias, but you will probably need to define it outside the extension. You could however define it as private, so that it is only seen in the same file.

    Assuming you have a class named AAA in your module AAA, it would look like this:

    private typealias OuterAAA = AAA.AAA
    
    extension Integrations {
        class AAA {
            class func setup(id: String) {
                OuterAAA.instance.setExternalUserId(id)
            }
        }
    }