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