Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 12 / iOS14 Widget "@main and must provide a main static function" error

Using Xcode 12 trying to create Widget app extension to my project.

Upon creating new Widget target I am getting the following error:

'Widget' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void.

enter image description here

like image 824
Vlad Avatar asked Jun 23 '20 06:06

Vlad


1 Answers

You are using name Widget, there is already a protocol called Widget in SwiftUI framework.

You should use some other name but if you really want to, add module name at start like SwiftUI.Widget

@main
struct Widget: SwiftUI.Widget {
    private let kind: String = "Widget"

    public var body: some WidgetConfiguration {
        IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider(), placeholder: PlaceholderView()) { entry in
            WidgetEntryView(entry: entry)
        }
        .configurationDisplayName("My Widget")
        .description("This is an example widget.")
    }
}
like image 190
Bilal Avatar answered Sep 30 '22 10:09

Bilal