Skip to content

Instantly share code, notes, and snippets.

@vnsam
Created July 30, 2021 13:44
Show Gist options
  • Save vnsam/f6170985eaed674c0acafd1e413c6b48 to your computer and use it in GitHub Desktop.
Save vnsam/f6170985eaed674c0acafd1e413c6b48 to your computer and use it in GitHub Desktop.
Injection ||| Setup Code
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
var injectionBundlePath = "/Applications/InjectionIII.app/Contents/Resources"
#if targetEnvironment(macCatalyst)
injectionBundlePath = "\(injectionBundlePath)/macOSInjection.bundle"
#elseif os(iOS)
injectionBundlePath = "\(injectionBundlePath)/iOSInjection.bundle"
#endif
Bundle(path: injectionBundlePath)?.load()
#endif
return true
}
}
Add - `-Xlinker -interposable` in `Other Linker Flags`
// Add this in any of the SwiftUI previews.
#if DEBUG
@objc class func injected() {
UIApplication.shared.windows.first?.rootViewController =
UIHostingController(rootView: ContentView())
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment