Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'main()' is only available in application extensions for iOS 14.0 or newer

I added widget target in my app, and I tried to the iOS 14 and newer condition for that, but I still got this error:

'main()' is only available in application extensions for iOS 14.0 or newer

@available(iOSApplicationExtension 14.0, *)
@main
struct Widget: SwiftUI.Widget {
    let kind: String = "Widget"

   var body: some WidgetConfiguration {
        IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
            WidgetEntryView(entry: entry)
        }
        .configurationDisplayName("My Widget")
        .description("This is an example widget.")
    }
}

That @available is the one that Xcode suggested me

screenshot

Could anyone help me on that?

like image 406
Robert kont Avatar asked Oct 03 '20 17:10

Robert kont


2 Answers

In the file where your put '@main', look at the target membership on the right sidebar, remove your main app as a target and leave your widget extension.

like image 148
Ray Xu Avatar answered Sep 20 '22 22:09

Ray Xu


If you added or already had an extension you should check that the deployment info for you extension is 14.0.

See screenshot: enter image description here

like image 31
Fernando Cardenas Avatar answered Sep 21 '22 22:09

Fernando Cardenas