如何解决此警告“ iOS 11.0中不推荐使用“ addressDictionary”:使用@properties”

时间:2019-04-04 22:33:45

标签: ios swift xcode

我需要在地图上获取地址,我使用addressDictionary,但是在Swift 4中已弃用,我该如何解决?

here is my code

2 个答案:

答案 0 :(得分:1)

使用.postalAddress

let address = loc.postalAddress
let street = address.street
...

答案 1 :(得分:1)

以下是此警告的better explanation

所描述的错误是CLPlacemark实例的addressDictionary属性的弃用错误。调用不赞成使用的方法时,Swift和Objective-C编译器可以浮现一些有关不赞成使用它的原因和/或解决该问题应采取的措施的信息。该信息(可选)由相关API的作者提供。

在这种情况下,CLPlacemark实现位于Objective-C中,因此该信息在其头文件中提供。来看一下,我们看到:@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary API_DEPRECATED("Use @properties", macos(10.8, 10.13), ios(5.0, 11.0), watchos(1.0, 4.0)); API_DEPRECATED宏告诉编译器引入API的位置以及在每个使其可用的OS中不推荐使用该API的时间。

相关问题