![](/img/trans.png)
[英]XCode - “'autorelease' is unavailable: not available in ARC mode”
[英]ARC unavailable methods in Swift
我能够使用Estimote nearables SDK看到一个有趣的案例
他们有一个ESTNearable
类,名为zone
。
// ENUM
typedef NS_ENUM(NSInteger, ESTNearableZone ) {
ESTNearableZoneUnknown = 0,
ESTNearableZoneImmediate,
ESTNearableZoneNear,
ESTNearableZoneFar,
};
// CLASS
@interface ESTNearable : NSObject <NSCopying, NSCoding>
// ...
@property (nonatomic, assign, readonly) ESTNearableZone zone;
// ...
@end
因此,当我尝试在Swift中使用此方法时,编译器会因该错误而失败:
据我所知,存在某种编译器错误,并且出于某种原因它认为我想使用来自NSObject
旧zone
方法- (struct _NSZone *)zone OBJC_ARC_UNAVAILABLE;
我可以毫无问题地使用该类的其他特定属性。
当我使用SDK时,我无法更改zone
方法的名称。 我相信我可以编写某种obj-c类,在那里添加一些新方法,它将返回原始方法的值,但我不想在我的项目中添加obj-c类。
是否有可能从swift调用此方法,因为我相信将为类实例调用正确的zone
方法?
提前致谢!
在这里,我发现了同样的问题。 我在那里回答得更深。 我找不到更好的东西,所以我继续我的旧假设。
我在Bridging Header中添加了这个类别。 它工作正常。
#import <EstimoteSDK/EstimoteSDK.h>
@interface ESTNearable (Ex)
/// Solving the compiler problem that "zone" method is unavailable in Swift
@property (readonly) ESTNearableZone nearableZone;
@end
// Implementation
@implementation ESTNearable (Ex)
- (ESTNearableZone)nearableZone
{
return self.zone;
}
@end
之后我在Swift中使用了nearableZone
方法
var zone = someNearable.nearableZone
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.