vishdeshmukh
(Vishwanath Deshmukh)
1
I have created swift extension for the class ViewController and defined one method in it. When I try to call same that method from the same Obj-c ViewController, it gives me an error below:
No visible @interface for 'ViewController' declares the selector 'testMe
My Code is as below:
Objective-C class
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self testMe]; // No visible @interface for 'ViewController' declares the selector 'testMe'
}
@end
Swift extension:
// ViewController+extnesion.swift
import UIKit
@objc public extension ViewController {
func testMe() {
print("Vish")
}
}
ksluder
(Kyle Sluder)
2
Your .m file needs to import the compatibility header that the Swift compiler emits.
vishdeshmukh
(Vishwanath Deshmukh)
3
Ah yeah, thank you. Below import made it worked.
import "ExtensionTest-Swift.h"