I have a class declared at the global scope and another class with the same name that is nested within some class.
class Address {
var someProperty: String?
}
class ThirdPartyAPI {
class Address {
var someOtherProperty: String?
init(fromAddress address: Address) {
self.someOtherProperty = address.someProperty
}
}
}
The question is: how can I refer to a global class instead of the inner one from its initialiser? In the example given I've got an error Value of type 'ThirdPartyAPI.Address' has no member 'someProperty'
, which means that compiler refers to the inner Address
instead of a global one.
You can refer to types uniquely by prepending the module name. So if
is defined in "MySuperApp" then you can refer to it as
MySuperApp.Address
:(But if you have a choice then try to avoid the ambiguity to make your code easier to understand.)
Use
typealias