[英]iOS: check system version in #define and do different stuff, compiler error
我使用MKReverseGeocoder
for iOS <5和CLGeocoder
for iOS> = 5,但是因为MKReverseGeocoder
被弃用而得到警告,然后我尝试做类似的事情:
#define SYSTEM_LOWER_THAN_5 ([[[UIDevice currentDevice] systemVersion] compare:@"5.0" options:NSNumericSearch] == NSOrderedAscending)
#if SYSTEM_LOWER_THAN_5
@interface TelstraLocationService () <MKReverseGeocoderDelegate>
#else
@interface TelstraLocationService ()
#endif
但是我收到一个错误:
预处理器表达式开始时的令牌无效
这是由只能在运行时评估的宏引起的。 有没有办法摆脱警告(不改变部署目标)?
如果您的目标是简单地摆脱编译器警告(因为您已经解决了任何潜在的问题并明确决定忽略它),请使用以下编译器指令包围触发代码:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// some code that uses something deprecated
#pragma clang diagnostic pop
您希望尽可能具体,以避免无意中忽略其他有效的弃用警告。 如果你之前和之后有另一个协议,那么只围绕MKReverseGeocoderDelegate
,否则只围绕整个@interface块:
// option 1
@interface TelstraLocationService () <
SomeProtocol
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
MKReverseGeocoderDelegate
#pragma clang diagnostic pop
AnotherProtocol>
// option 2
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@interface TelstraLocationService () <MKReverseGeocoderDelegate>
#pragma clang diagnostic pop
围绕对reverseGeocoder:didFindPlacemark:
任何调用reverseGeocoder:didFindPlacemark:
或reverseGeocoder:didFailWithError:
使用相同的编译器指令来为它们静默弃用警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.