Skip to content

Instantly share code, notes, and snippets.

@dezinezync
Created July 28, 2021 06:05
Show Gist options
  • Save dezinezync/1ff79607462de44011a9fb1bbf8c7e73 to your computer and use it in GitHub Desktop.
Save dezinezync/1ff79607462de44011a9fb1bbf8c7e73 to your computer and use it in GitHub Desktop.
Xcode 13 Beta 3 and above: Workaround for UIApplication usage in SPM packages
private func someFunc() -> Bool {
guard let aClass = NSClassFromString("UIApplication") else {
return false
}
// fetch properties as necessary.
let layoutDirection = UIUserInterfaceLayoutDirection(rawValue: aClass.value(forKeyPath: "sharedApplication.userInterfaceLayoutDirection") as! Int)
// use runtime inspection to determine return value type.
let state = UIApplication.State(rawValue: aClass.value(forKeyPath: "sharedApplication.applicationState") as! Int)
// use the values as necessary.
return state == .active || layoutDirection == .rightToLeft
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment