How to detect SwiftUI usage programmatically in an iOS application

Viewed 590

I am working on a library for iOS, and i need to know if the application using the library is running SwiftUI or not so that i can handle things appropriately.

Is there a way to find this out programmatically in Objective-C?

1 Answers

In the end i did this.

  1. Get the root or key window of the application.

  2. Check if it's class name contains "UIHostingController"

  3. Also nil check for this: NSClassFromString(@"SwiftUI._UIGraphicsView")

You could also check for other swift ui classes but this has covered all cases so far.

Related