问题
I was able to see an interesting case using Estimote nearables SDK
They have a class ESTNearable with property called 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
So when I try to use this method in Swift, compiler fails with that error:
As I understand there is some kind of compiler bug and for some reason it believes that I want to use old zone method from NSObject - (struct _NSZone *)zone OBJC_ARC_UNAVAILABLE; I can use other specific properties of that class without any problems.
As I use an SDK I can not change the name of the zone method. I believe I can write some kind of obj-c category, add some new method there, which will return value of original one, but I do not want to add obj-c classes in my project.
Is there any possibility to call this method from swift as I believe correct zone method will be called for class instances?
Thanks in advance!
回答1:
Here I found the same question. I answered more deeply there. I could not find something more good, so I went ahead with my old assumptions.
I Added this category to Bridging Header. It worked fine.
#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
After that I just used nearableZone method in Swift
var zone = someNearable.nearableZone
来源:https://stackoverflow.com/questions/30599486/arc-unavailable-methods-in-swift