I'm fairly new to extensions in iOS and would like to use SwiftUI for the extension
so I've subclassed UIHostingController and then I've tried to access the extensionContext as I was previously in a UIViewController I had previously set as the class in the storbyboard.
I thought this was a complete implemention of UIViewController? It appears extensionContext is only populated when you use a UIViewController as the root?
How can I go about rendering SwiftUI view and pass the provided items down?
class ShareViewController: UIViewController {
// @IBOutlet var container: UIView!
override func viewDidLoad() {
super.viewDidLoad()
guard let extensionItems = extensionContext?.inputItems as? [NSExtensionItem] else {
return
}
// in the debugger I get here and theres 1 item in the extensionItems
for extensionItem in extensionItems {
if let itemProviders = extensionItem.attachments {
class MainSwiftUIView: UIHostingController<MainUIView> {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder, rootView: MainUIView(urlShared: ""))
}
override func viewDidLoad() {
super.viewDidLoad()
guard let extensionItems = self.extensionContext?.inputItems as? [NSExtensionItem] else {
return // debugger exits here... :(
}
// the debugger doesn't reach here
for extensionItem in extensionItems {