我有一个在全局范围内声明的类,另一个具有相同名称的类嵌套在某个类中.
class Address { var someProperty: String? } class ThirdPartyAPI { class Address { var someOtherProperty: String? init(fromAddress address: Address) { self.someOtherProperty = address.someProperty } } }
问题是:如何从初始化中引用全局类而不是内部类?在给出的示例中,我遇到了错误Value of type 'ThirdPartyAPI.Address' has no member 'someProperty'
,这意味着编译器引用内部Address
而不是全局内部.
使用 typealias
class Address { var someProperty: String? } typealias GlobalAddress = Address class ThirdPartyAPI { class Address { var someOtherProperty: String? init(fromAddress address: GlobalAddress) { self.someOtherProperty = address.someProperty } } }