如何使用objective-c向接口公开自定义init implementation



我简单地定义了Swift协议,如下所示:

@objc protocol MobileKeyable {
var assaAbloyLockServiceCode: Int { get }
}

然后我在objective-c类中使用它:

- (id)initWithComposition: (id<MobileKeyable>)composition {
self = [super init];
if (self) {
_lockServiceCodes = @[@([composition assaAbloyLockServiceCode])];
}
return self;
}

然后我想初始化Swift中的控制器,如下所示:

let composition = //here MobileKeyable
MobileKeysController(composition: composition)

因此,我需要将初始化器公开到objective-c接口:

#import "MyProject-Swift.h"
@interface MobileKeysController : NSObject <MobileKeysManagerDelegate>
- (instancetype) initWithComposition: (id<MobileKeyable>)composition;
@end

但是这里我有一个错误:MyProject-Swift.h file not found。为什么?

也许Xcode试图避免一些循环。。。只是假设。尝试转发声明

@protocol MobileKeyable;
@interface MobileKeysController : NSObject <MobileKeysManagerDelegate>
- (instancetype) initWithComposition: (id<MobileKeyable>)composition;
@end

最新更新