6

I've created a Widget and I'm adding @main on top of the declaration.

However, when I switch to the Widget extension target and run it, I get the error 'main' attribute can only apply to one type in a module because I also have a @main in my main app file (the entry point). I need to, depending on whether I want to run the app or the widget target, remove the @main from the target that I don't want to run, run it and later on add it.

Is there something I'm doing wrong? I have tried to look this up and I haven't found any mention of it.

Thanks in advance!

noloman
  • 11,411
  • 20
  • 82
  • 129
  • You likely have both files that have `@main` added to the widget target. Just deselect the one that is included in your main app. Whatever you need from the body of the file in the main app can be put in a separate subview that can be shared between the targets. But it is hard to tell exactly what is going on since you haven't shared any code or setup. – lorem ipsum Dec 13 '21 at 17:32

1 Answers1

4

You can only have one entry-point per target. You might have one of the two files (defining @main) included in the wrong target.

Open up both files in XCode, then open Inspectors and check if the Widget-related file target-membership is the WidgetExtension (only) and the App related file in the Apps target.

This might resolve your issue.

Dominik Seemayr
  • 830
  • 2
  • 12
  • 30