I have framework that written in Swift like this.
import Foundation
import WebKit
import ObjectiveC
public extension WKWebView {
public func someFunc(_ completionHandler:@escaping (_ capturedImage: UIImage?) -> Void) {
//Some code
}
}
When I build the frameworks and import to Objective-C code that use Cocoapods for Dependency Manager. I Can't call above someFunc function. The error said this:
No visible @interface for 'WKWebView' declares the selector 'someFunc'
This is how I implement Swift framework in Objective-C:
#import <Foundation/Foundation.h>
#import <ProjectName-umbrella.h>
@implementation CapturerDefault
- (void)captureWebViewScreenWith:(UIView *)containerView
andCompletionHandler:(void (^)(UIImage *))completion {
WKWebView *webView = [self findWebViewInViewController:containerView];
[webView someFunc: resultImage] //The error show here.
}
}
What is wrong? Did i miss something?
I tried the following steps and it works for me:
Swift file:
import WebKit
extension WKWebView {
@objc public func someFunc() {
}
}
Objective C file:
#import "ViewController.h"
#import "Sample-Swift.h"
#import <WebKit/WebKit.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
WKWebView *wbView = [[WKWebView alloc]init];
[wbView someFunc];
}
Credits to: "Expected ';' after top level declarator" under Swift
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments