7

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?

Robert kont
  • 165
  • 1
  • 8

3 Answers3

8

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.

Ray Xu
  • 130
  • 5
5

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

Fernando Cardenas
  • 1,203
  • 15
  • 19
0

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

qian qian
  • 11
  • 1