While looking at WWDC 2022 - Dive into App Intents, my attention was caught by two sentences pronounced by the speaker Michael Gorbach during the presentation:
My app does not run any line of the above code. And yet the mere presence of this type in my target has consequences. Surely some technique(s) I'm totally unaware of is at play here.
The transcript mentions "literals", "build time" and "build process", although a close inspection of the build logs did not make anything pop up to my eyes (maybe I did not look close enough).
Has anyone some insight about the techniques that are at play here? The requirement for "literals" make me think of a pre-release of SE-0359. The "during your build process" snippet may just refer to some Xcode proprietary technology, perhaps akin to package plugins. Yet I can't quite figure out what "information received from the Swift compiler as it runs on your code" refers to.
When I saw this, I just assumed that this was a build tool package plugin at play, which would somehow scan my source code and generate the entitlements needed. But I haven't looked into any of that, so this is pure speculation.
This is indeed build time extraction. There is an "Extract app intents metadata" step in the build log. The way this works is that the Swift compiler outputs some information that it generates while compiling your code, which describes what types are available in your code, as well as type-level and some value-level information from your App Intents method implementations. This information is parsed by another tool which generates a metadata.appintents directory in your built product which contains files that describe your intents, and other information we need to know without running your app, such as information needed to render your intents in Shortcuts.
The interaction with SE-0359 is basically that Swift uses an underscored version of that feature to force the operand to be a literal so that the static extraction of these values by that secondary tool cannot fail.
I find out that there is no way for me to exclude the "Extract app intents metadata" step, even if all AppIntentes related coded is hidden behind some debug flag.
It just goes like "Extracted no relevant App Intents symbols, skipping writing output" and that step takes it 13 seconds for my app.
The only way is to replace the executable for appintentsmetadataprocessor. Anyone experiences this step to take so long too?
When I use cocoaPods to manager my AppIntent file, I always failed to the "Extract app intents metadata" step. If anybody knows about why or give me some clue?