3

I have a WidgetKit widget with an intent handler. Currently it uses hard coded values and I'm trying to extend it to work with dynamic values.

I did this successfully on another project but am struggling with this one.

Here's what I've done:

  1. Created an Intent Handler target Screenshot

  2. Added a custom type

  3. Added that type as a parameter

  4. Added the intent definition as a member of the new target Screenshot

  5. There is a custom class name for the intent

  6. Custom code is successfully generated Screenshot

  7. Set the IntentHander class to implement ThemeSelectionIntentHandling Screenshot

As you can see, this fails with the error Cannot find type 'ThemeSelectionIntentHandling' in scope.

The target that fails is the Intent Handler:

/Users/lewissmith/code/wtw-ios-app/WTWIntents/IntentHandler.swift:12:3: error: cannot find type 'ThemeSelectionIntentHandling' in scope
, ThemeSelectionIntentHandling {
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Command EmitSwiftModule failed with a nonzero exit code

Screenshot Screenshot

If I remove implementing ThemeSelectionIntentHandling then it builds as expected.

DTS won't help me because the project uses Cocoapods.

Does anyone have any ideas?

lewis
  • 2,936
  • 2
  • 37
  • 72
  • 1
    Have you done this step: [>In the File inspector, verify that the containing app, the widget extension, and the Intents extension all include the intent definition file.](https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget) – leanne Aug 06 '22 at 20:01
  • Which target is failing to build? (In Xcode, detailed build info is available in the Report navigator, cmd-9 shows it). This sounds like your generated class isn't included in some target where it's needed. – asyncawait Aug 08 '22 at 19:27
  • @leanne this is step 4 in my question right(?). The Intent Definition is a member of the main (containing) app, the widget extension and the intents extension. Am I missing something, does that look wrong to you? – lewis Aug 09 '22 at 07:27
  • @asyncawait it's the intent handler that fails compilation. I've added some extra screenshots and info to the question, thank you. – lewis Aug 09 '22 at 07:33
  • 1
    Gotcha - did your ThemeSelectionIntent.swift maybe not get added to your intent handler target? That's what it sounds like. Check in the right pane, if it looks good there, go to the target, look in Build Phases > Compile Sources and make sure its there, too. – asyncawait Aug 09 '22 at 16:43
  • The intent handler is failing because, for some reason, it's not "seeing" that custom protocol. So, the real question is why... The only other item I found with a similar result involved "adding the NSUserActivityTypes key to the main app Info.plist file with the DynamicIntent name". I don't think missing that would cause the protocol to be out of scope, though... – leanne Aug 09 '22 at 22:16
  • 1
    @asyncawait you are right! for whatever reason in the intent handler extension the intent definition had been added as a resource and not code. once it was code it was found. if you write an answer I'll give you the bounty – lewis Aug 11 '22 at 08:56
  • 1
    @leanne you were definitely on the right track, thank you so much for helping me. in the end the intent handler was part of the target but as a resource not code – lewis Aug 11 '22 at 08:58
  • Right on! Glad it worked out. – asyncawait Aug 12 '22 at 02:30

1 Answers1

0

you could try to change the build setting in Widget extension "Build Setting" -> search for "intent class" -> change the language to "Swift" and run again.

day
  • 73
  • 8