I have written one class function in one swift class then trying to access the same from one objectiveC class getting No known class method for selector 'myMethodName'. I have also done #import "ProjectName-Swift.h"
. It was working properly with Xcode below 10.1 . Please help me at the earliest. Thanks in advance.
import UIKit
typealias LoginCompletionHandler = (_: Bool) -> Void
class SCLoginViewController: UIViewController {
var myLoginCompletionBlock: LoginCompletionHandler? = nil
// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
}
//PRAGMA:- Class Methods
class func showOnNavigation(navigationController:UINavigationController, completionBlock:@escaping LoginCompletionHandler) {
let vc = SCLoginViewController.init(nibName: "SCLoginViewController", bundle: nil)
vc.myLoginCompletionBlock = completionBlock
navigationController.pushViewController(vc, animated: true)
}
}
#import "LoginOptionVC.h"
#import "Project-Swift.h"
@interface LoginOptionVC () <>
@end
@implementation LoginOptionVC
- (instancetype)initWithBarButtonType:(BarButtonType)btnType showClubLogo:(BOOL)showLogo onCompletion:(CompletionHandler) completionBlock {
self = [[ClubLoginOptionVC alloc]initWithNibName:@"ClubLoginOptionVC" bundle:nil];
if (self) {
self.myCompletionBlock = completionBlock;
}
return self;
}
#pragma mark - View LifeCycle
- (void)viewDidLoad {
[super viewDidLoad];
- (IBAction)clickLogin:(id)sender {
[SCLoginViewController showOnNavigationWithNavigationController:self.navigationController completionBlock:^(BOOL isSuccess) {
if (isSuccess) {
NSLog(@"logged in ");
}
if (self.myCompletionBlock) {
self.myCompletionBlock(isSuccess);
}
}];
}
}
Addition to Scriptable's answer. If you want to expose all function to Objective-C in a class. Then add @objcMembers
attribute.
@objcMembers class MyController: UIViewController {
class func showOnNavigation(navigationController:UINavigationController, completionBlock:@escaping LoginCompletionHandler) {
}
}
By way of adding @objcMembers attribute in a class, you no need to add @objc
attribute in functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With