Objective-C クラスで Swift を使用しようとしていますが、構文に問題があるか、可能であるとしても問題があります。以下は私が試しているものです。
迅速:
@objc protocol MyProtocol {
var someManager: MyManager? { get set }
var someState: MyState { get set }
}
extension MyProtocol {
func didLoad(delegate: MyProtocol) {
}
}
class ViewController: MyProtocol {
var someManager: MyManager?
var someState: MyState = .Unknown
override func viewDidLoad() {
super.viewDidLoad()
didLoad(self as MyProtocol)
}
}
目的 C:
@interface ViewController : UIViewController<MyProtocol>
@end
@interface ViewController()
@property (nonatomic, assign) MyManager *someManager; //?? Error: Illegal redeclaration of property in class extension ‘ViewController’ (attribute must be ‘readwrite’, while its primary must be ‘readonly’)
@property (nonatomic, assign) MyState someState; //??
@end
@implementation HomeViewController
-(void)viewDidLoad {
[super viewDidLoad];
[self didLoad:(self as MyProtocol)] //??
}
Objective-C ViewController を動作させるにはどうすればよいですか? Swiftでどのように機能するかの例があります。助けてくれてありがとう。