Skip to content

Instantly share code, notes, and snippets.

@revblaze
Last active February 1, 2021 22:56
Show Gist options
  • Save revblaze/d44b9dd52436c26067ea118c0c14c1d1 to your computer and use it in GitHub Desktop.
Save revblaze/d44b9dd52436c26067ea118c0c14c1d1 to your computer and use it in GitHub Desktop.
Easy and quick device conditionals – a basic necessity.
// import UIKit
// import SwiftUI
struct Device {
static let phone = UIDevice.current.userInterfaceIdiom == .phone
static let pad = UIDevice.current.userInterfaceIdiom == .pad
static let mac = UIDevice.current.userInterfaceIdiom == .mac
static let tv = UIDevice.current.userInterfaceIdiom == .tv
static let width = UIScreen.main.bounds.size.width
static let height = UIScreen.main.bounds.size.height
static let size = UIScreen.main.bounds.size
}
@revblaze
Copy link
Author

revblaze commented Feb 1, 2021

ie.

if Device.phone { ... } else { is .pad }

.frame(width: Device.width)

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