Suppose there are two class one in swift and other is in objective-c class in same project.
In swift class i declared delegate and i want to set that delegate in objective c class.
I have done this following way ...
import UIKit
@objc public protocol SwiftLoginVCDelegate: class {
}
@objc public class SwiftLoginViewController: UIViewController {
@IBOutlet var txtUserName: UITextField!
@IBOutlet var txtPassword: UITextField!
@IBOutlet var btnLogin: UIButton!
var delegate: SwiftLoginVCDelegate?
override public func viewDidLoad() {
super.viewDidLoad()
self.txtPassword.text = "XYZ"
self.txtPassword.text = "123"
self.btnLogin.backgroundColor = UIColor.blue
}
@objc public func testObjective(){
print("Swift class is integrated in objective c project")
}
the objective c class is
#import "Mediator.h"
@class SwiftLoginViewController;
@protocol SwiftLoginVCDelegate;
@interface LoginMediator : Mediator
@end
Implementation Class is
#import "xyz-Swift.h"
@class SwiftLoginViewController;
@implementation LoginMediator
-(void)onRegister
{
// line 1: [(XYZController*)self.viewComponent setDelegate:self];
line 2 : [(SwiftLoginViewController*)self.viewComponent setDelegate:self];
[objectVC testObjective];
}
If u check the onRegister Method , In line No 1 delegate is set using objective c, which is commented now , but i want to set same delegate in swift 4 , line no 2, when I try to set delegate in swift 4 I am getting following error
No visible @interface for 'SwiftLoginViewController' declares the selector 'setdelegate';
Note :
One more that i am able to access all the var and function defined in swift class to objective c Class. I am not able to set the Delegate in objective c Class which is declared in swift Class.
Can any one has any idea what i am doing wrong in above code ? All inputs are appreciated.
@objc weak public var delegate: SwiftLoginVCDelegate?
– Though