Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No known class method for selector in objectiveC class found written in swift class

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);
        }
    }];
}
}
like image 928
Tapash Mollick Avatar asked Jan 01 '23 10:01

Tapash Mollick


1 Answers

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.

like image 120
Vinoth Vino Avatar answered Jan 03 '23 23:01

Vinoth Vino