Skip to content

Instantly share code, notes, and snippets.

@agiletortoise
Created August 24, 2023 18:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agiletortoise/e34b788304736137f1ffebe4c5ba7996 to your computer and use it in GitHub Desktop.
Save agiletortoise/e34b788304736137f1ffebe4c5ba7996 to your computer and use it in GitHub Desktop.
Intent Dependency
// create an object to inject
struct AppIntentDependencyManager {
func hello() {}
// whatever methods you need....
}
// in didFinishLaunching or similar inject your dependency like...
if #available(iOS 16.0, *) {
AppDependencyManager.shared.add(key: "AppIntentDependencyManager", dependency: AppIntentDependencyManager())
}
// in your Intent definition, use below to get access to the injected manager
@Dependency(key: "AppIntentDependencyManager") var dependencyManager: AppIntentDependencyManager
// in `perform` or whatever in the intent, you can call
dependencyManager.hello()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment