Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created January 14, 2023 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannxou/4323ce24c20452a683f8ad2a28cebbf8 to your computer and use it in GitHub Desktop.
Save yannxou/4323ce24c20452a683f8ad2a28cebbf8 to your computer and use it in GitHub Desktop.
Swift: Check if app running as Catalyst with 'Optimized for mac' setting enabled
// Credit: https://steipete.com/posts/forbidden-controls-in-catalyst-mac-idiom/
extension UIDevice {
/// Checks if we run in Mac Catalyst Optimized For Mac Idiom
var isCatalystMacIdiom: Bool {
if #available(iOS 14, *) {
return UIDevice.current.userInterfaceIdiom == .mac
} else {
return false
}
}
}
@yannxou
Copy link
Author

yannxou commented Jan 16, 2023

Alternative (if native macOS is also supported):

var isNativeMacAppOrCatalystOptimized: Bool {
#if os(iOS)
    return UIDevice.current.userInterfaceIdiom == .mac
#elseif os(macOS)
    return true
#endif
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment