Programmatically get screen size in Mac OS X

In Swift 4.0 you can get the screen size of the main screen:

if let screen = NSScreen.main {
    let rect = screen.frame
    let height = rect.size.height
    let width = rect.size.width
}

If you look for the size of the screen with a particular existing window you can get it with:

var window: NSWindow = ... //The Window laying on the desired screen
var screen = window.screen!
var rect = screen.frame
var height = rect.size.height
var width = rect.size.width

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)