Created
June 16, 2015 05:47
-
-
Save wmarbut/3bab57cebd7787f245b8 to your computer and use it in GitHub Desktop.
Get all available display resolutions on your machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// Created by grep-awesome on 6/15/15. | |
// | |
import Foundation | |
import CoreGraphics | |
var displayConfig: CGDisplayConfigRef = nil | |
let mainDisplayID = CGMainDisplayID() | |
var displayMode = CGDisplayCopyDisplayMode(mainDisplayID).takeRetainedValue() | |
var width = CGDisplayModeGetWidth(displayMode) | |
var height = CGDisplayModeGetHeight(displayMode) | |
print("current size: \(width)x\(height)\n") | |
print("available sizes:\n") | |
var modes = CGDisplayCopyAllDisplayModes(mainDisplayID, nil).takeRetainedValue() | |
let modesCount = CFArrayGetCount(modes) - 1 | |
for i in 0...modesCount { | |
var mode: CGDisplayModeRef = unsafeBitCast(CFArrayGetValueAtIndex(modes, i), CGDisplayModeRef.self) | |
var width = CGDisplayModeGetWidth(mode) | |
var height = CGDisplayModeGetHeight(mode) | |
print("\t\(width)x\(height)\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment