Last active
March 6, 2022 11:18
-
-
Save lilyball/569d5ba0f1b0961a15c0 to your computer and use it in GitHub Desktop.
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
| import CoreGraphics | |
| func printDisplays() { | |
| var displayCount: UInt32 = 0; | |
| var result = CGGetActiveDisplayList(0, nil, &displayCount) | |
| if (result != 0) { | |
| println("error: \(result)") | |
| return | |
| } | |
| let allocated = Int(displayCount) | |
| var activeDisplays = UnsafeMutablePointer<CGDirectDisplayID>.alloc(allocated) | |
| result = CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount) | |
| if (result != 0) { | |
| println("error: \(result)") | |
| return | |
| } | |
| println("\(displayCount) displays:") | |
| for i in 0..<displayCount { | |
| println("[\(i)] - \(activeDisplays[Int(i)])") | |
| } | |
| activeDisplays.dealloc(allocated) | |
| } | |
| printDisplays() |
@razic if result != CGError.Success
- var activeDisplays
+ let activeDisplaysadjusted for swift 5.2:
import AVFoundation
func printDisplays() {
var displayCount: UInt32 = 0;
var result = CGGetActiveDisplayList(0, nil, &displayCount)
if result != .success {
print("error: \(result)")
return
}
let allocated = Int(displayCount)
let activeDisplays = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: allocated)
result = CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount)
if result != .success {
print("error: \(result)")
return
}
print("\(displayCount) displays:")
for i in 0..<displayCount {
print("[\(i)] - \(activeDisplays[Int(i)])")
}
activeDisplays.deallocate()
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kballard I tried to run this but getting error about being unable to compare
resultto0. I'm using Xcode 7.0 (7A220) and on the GM Release of El Capitan. I can callresult.rawValueand compare that with0though.