Skip to content

Instantly share code, notes, and snippets.

@AbodiDawoud
Created October 22, 2025 17:56
Show Gist options
  • Select an option

  • Save AbodiDawoud/8e0a2198ab575f2a3a947465481416ff to your computer and use it in GitHub Desktop.

Select an option

Save AbodiDawoud/8e0a2198ab575f2a3a947465481416ff to your computer and use it in GitHub Desktop.
//
// UIScreen++.swift
// UIScreen++
import SwiftUI
extension UIScreen {
var name: String {
return self.value(forKey: "_name") as! String
}
var configuration: NSObject {
return self.value(forKey: "displayConfiguration") as! NSObject
}
var displayIdentity: NSObject {
return self.value(forKey: "displayIdentity") as! NSObject
}
var capabilities: NSDictionary {
return self.value(forKeyPath: "_capabilities") as! NSDictionary
}
var isPerformingSystemSnapshot: Bool {
return self.value(forKey: "_isPerformingSystemSnapshot") as! Bool
}
var hasWindows: Bool {
return self.value(forKey: "_hasWindows") as! Bool
}
var isMainScreen: Bool {
return self.value(forKey: "mainScreen") as! Bool
}
var isOverscanned: Bool {
return self.value(forKey: "_isOverscanned") as! Bool
}
var isExternal: Bool {
return self.value(forKey: "_isExternal") as! Bool
}
var isEmbeddedScreen: Bool {
return self.value(forKey: "_isEmbeddedScreen") as! Bool
}
var isFocusSystemLoaded: Bool {
return self.value(forKey: "_isFocusSystemLoaded") as! Bool
}
var isForceTouchCapable: Bool {
return self.value(forKey: "_isForceTouchCapable") as! Bool
}
var isRotatable: Bool {
return self.value(forKey: "_isRotatable") as! Bool
}
var isWorkspaceCapable: Bool {
return self.value(forKey: "_isWorkspaceCapable") as! Bool
}
var isCarScreen: Bool {
return self.value(forKey: "_isCarScreen") as! Bool
}
var supportsBrightness: Bool {
return self.value(forKey: "_supportsBrightness") as! Bool
}
var supportsDragging: Bool {
return self.value(forKey: "_supportsDragging") as! Bool
}
var supportsDeferredFocus: Bool {
return self.value(forKey: "_supportsDeferredFocus") as! Bool
}
var supportsCloning: Bool {
return self.configuration.value(forKey: "cloningSupported") as! Bool
}
var pointsPerInch: Double {
return self.value(forKey: "_pointsPerInch") as! Double
}
var refreshRate: Double {
return self.configuration.value(forKey: "refreshRate") as! Double
}
var latency: Double {
return self.configuration.value(forKey: "latency") as! Double
}
var pointScale: Double {
return self.configuration.value(forKey: "pointScale") as! Double
}
var nativeOrientation: Double {
return self.configuration.value(forKey: "nativeOrientation") as! Double
}
func debug() {
print(
"""
Name: \(self.name)
Identity: \(self.displayIdentity)
PointsPerInch: \(self.pointsPerInch)
MainScreen: \(self.isMainScreen)
HasWindows: \(self.hasWindows)
Overscanned: \(self.isOverscanned)
External: \(self.isExternal)
EmbeddedScreen: \(self.isEmbeddedScreen)
FocusSystemLoaded: \(self.isFocusSystemLoaded)
ForceTouchCapable: \(self.isForceTouchCapable)
Rotatable: \(self.isRotatable)
CarScreen: \(self.isCarScreen)
WorkspaceCapable: \(self.isWorkspaceCapable)
SupportsBrightness: \(self.supportsBrightness)
SupportsDragging: \(self.supportsDragging)
SupportsDeferredFocus: \(self.supportsDeferredFocus)
PerformingSystemSnapshot: \(self.isPerformingSystemSnapshot)
<---------------->
Capabilities: \(self.capabilities)
Configuration: \(self.configuration)
"""
)
}
}
struct ContentView: View {
let shared = UIScreen.main
var body: some View {
Form {
Section {
VStack {
Text("Screen Info")
.font(.system(.title, design: .rounded, weight: .heavy).smallCaps())
.foregroundStyle(.teal)
Text("Useful private APIs exposed via `UIScreen` class into Swift")
.font(.callout)
.foregroundStyle(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal)
}
.listRowBackground(Color.teal.opacity(0.1))
.frame(maxWidth: .infinity)
}
Section {
LabeledContent("Name", value: shared.name)
LabeledContent("Identity", value: "\(shared.displayIdentity)")
LabeledContent("RefreshRate", value: "\(shared.refreshRate)")
LabeledContent("Latency", value: "\(shared.latency)")
LabeledContent("PointScale", value: "\(shared.pointScale)")
LabeledContent(
"PointsPerInch",
value: String(shared.pointsPerInch.formatted(.number.precision(.fractionLength(2))))
)
LabeledContent("NativeOrientation", value: "\(shared.nativeOrientation)")
}
Section {
LabeledContent("MainScreen", value: shared.isMainScreen.str)
LabeledContent("HasWindows", value: shared.hasWindows.str)
LabeledContent("Overscanned", value: shared.isOverscanned.str)
LabeledContent("External", value: shared.isExternal.str)
LabeledContent("Rotatable", value: shared.isRotatable.str)
LabeledContent("CarScreen", value: shared.isCarScreen.str)
LabeledContent("EmbeddedScreen", value: shared.isEmbeddedScreen.str)
LabeledContent("FocusSystemLoaded", value: shared.isFocusSystemLoaded.str)
LabeledContent("ForceTouchCapable", value: shared.isForceTouchCapable.str)
LabeledContent("WorkspaceCapable", value: shared.isWorkspaceCapable.str)
LabeledContent("PerformingSystemSnapshot", value: shared.isPerformingSystemSnapshot.str)
}
Section {
LabeledContent("Supports Dragging", value: shared.supportsDragging.str)
LabeledContent("Supports Cloning", value: shared.supportsCloning.str)
LabeledContent("Supports Brightness", value: shared.supportsBrightness.str)
LabeledContent("Supports DeferredFocus", value: shared.supportsDeferredFocus.str)
}
Section {
DisclosureGroup("Capabilities") {
ScrollView([.horizontal]) {
Text("\(shared.capabilities)").foregroundStyle(.secondary)
}.padding(.leading, -15)
}.foregroundStyle(.primary, .teal)
DisclosureGroup("Configuration") {
ScrollView([.horizontal]) {
Text("\(shared.configuration)").foregroundStyle(.secondary)
}.padding(.leading, -15)
}.foregroundStyle(.primary, .teal)
}
}
.listSectionSpacing(.custom(18))
}
}
extension Bool {
var str: String {
String(self).capitalized
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment