I'm trying to find a way of adding a condition for checking is an extension target in Framework (not main app). Is it possible relying on #available(iOSApplicationExtension, *)
with some parameters adjustments?
@objc public extension UIView {
var isAccessibilityCategory: Bool {
if #available(iOSApplicationExtension, *) {
return self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory
} else {
return UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory
}
}
}
How to detect if code is running in Main App or App Extension Target? - doesn't work, because the framework doesn't know about extension targets
#available
statement cannot be used for detecting target type like application extension. That can only detect what operating system and what version of that OS the app is run on.#available
was created so that you can use system capabilities that only became available in newer OS versions than your minimum target dependency - such as using Combine or SwiftUI in a project targeting iOS13 <. It cannot be used for running custom logic for app extensions rather than in the app target itself.UIApplication.shared
correctly at compile-time, not runtime