I've created the Swift framework and integrated into ObjC project.
Now, I want to pass/access delegate handler in ObjC.
Swift Framework contains UIViewController with close and submit button.
ListViewController.swift SwiftFramework
public protocol ListHandler {
func submit(options: String)
func close()
}
public class ListViewController: UIViewController {
public var handler: ListHandler?
@objc func dismiss(_ sender: UIButton) {
handler?.close()
}
@objc func submit(_ sender: UIButton) {
handler?.submit(options: "Done")
}
}
Created MyApp-Bridginh-Header.h
And SwiftWrapper.swift to show ListViewController
import SwiftFramework
@objc public class SwiftWrapper: NSObject {
@objc public var controller: ListViewController?
override init() {
print("Working")
}
@objc public func showListScreen() -> UIViewController {
self.controller = ListViewController(title: "List")
/*
IMPORTANT: How I can pass this to ObjC called controller?
*/
// self.controller?.handler =
return self.controller!
}
}
Finally in objC view controller, able to show List screen but can't pass delegate and handle submit/close button actions.
ProductListViewController.m
#import "MyApp-Swift.h"
SwiftWrapper *wrapper = [[SwiftWrapper alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[wrapper showListScreen]];
[self presentViewController:navController animated:YES completion:nil];
How to access here?
Example project repository: Swift Framework: https://github.com/harshal-wani/SwiftListFramework ObjC project: https://github.com/harshal-wani/SwiftFrameworkDelegateExample
Appreciate your help and suggestions.
Thanks
@objc? also where are you trying to access this delegate? I can't see it in your code