Swift

Swift:1mmを取得する

var mm: CGFloat = 0.0

for screen in NSScreen.screens {
    if screen.frame.contains(self.superview!.window!.frame.origin) {
        let key = NSDeviceDescriptionKey(rawValue: "NSScreenNumber")
        let id = screen.deviceDescription[key] as! UInt32
        let realSize: CGSize = CGDisplayScreenSize(id)
        let virtualSize = screen.deviceDescription[NSDeviceDescriptionKey.size] as! NSSize
        mm = virtualSize.width / realSize.width  
    }
    break
}

MacBookのディスプレイなら正しく1mmが取れるが,外部ディスプレイの場合正しく取れない場合もある模様.