Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initiate with SwiftUI content view instead of ActionViewController in iOS Action Extention

Tags:

ios

swift

swiftui

enter image description hereMy whole code base is in UIKit. I want to build my action extension module using swiftUI.

As I can add NSExtensionPrincipalClass as the initial entry point to the extension UI. How can I set the initial entry point to a swiftUI content view.

struct ActionExtensionInitialView: View {
    var body: some View {
        Text("Hello, World!")
    }
}
like image 693
Priyam Dutta Avatar asked Feb 06 '20 10:02

Priyam Dutta


1 Answers

Your principal class can look like the following (tested & worked with Xcode 11.2)

class ActionViewController: UIHostingController<AnyView> {

    // override designated initialiser
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        let contentView = ActionExtensionInitialView() // << SwiftUI root view
        super.init(rootView: AnyView(contentView))
    }

    @objc required dynamic init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

backup

like image 51
Asperi Avatar answered Nov 14 '22 20:11

Asperi