Robert kont
Robert kont

Reputation: 165

'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?

Upvotes: 7

Views: 6043

Answers (3)

qian qian
qian qian

Reputation: 11

does your project use xcodegen ? if no, just change target version. if yes, config your project.yml, and remember configure your target iOS version 14.1 but not 14.0. you can also see this Add deploymentTarget to widget in XcodeGen

Upvotes: 0

Fernando Cardenas
Fernando Cardenas

Reputation: 1232

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

Upvotes: 5

Ray Xu
Ray Xu

Reputation: 160

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.

Upvotes: 9

Related Questions