I'm trying to use a Swift in an Objective-C class, but having trouble with the syntax or even if it's possible. Below is what I'm trying.
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)
}
}
Objective-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)] //??
}
How can I get the Objective-C ViewController to work? I have an example of how it should work in Swift. Thanks for any help.