My open source library needs to be able to call UIApplication.shared.preferredContentSizeCategory
. But UIApplication.shared
is unavailable in extensions. The build error suggests that I find a view controller-based way to solve my problem, but I'm writing a library, so I don't have access to any view controllers. Is there a way to get the root view controller of an extension, or a way to get the outermost UITraitEnvironment
?
I support iOS 9+, but this feature could be 10+ if that makes it possible.
self.view.window.preferredContentSizeCategory
? – UnbiddenUITraitCollection
, and I want to find the current trait environment's current trait collection. You can see the reasoning here. I could just compile that part out, but I'd rather actually support dynamic type in extensions. – MinutessharedApplication
actually exists in extensions, just artificially blocked due to how Apple have set up their extensions lifecycle.UIApplication.value(forKey: "sharedApplication") as! UIApplication
will give you what you want. ;-) – UnbiddenUIScreen.main.preferredContentSizeCategory
return? I thinkUIScreen.main
is available in extensions. – Unbidden