Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

deviceDescription

INDEX>AppKit>NSScreen

スクリーンのデバイス辞書を返します

Objective-C

@property(readonly, copy) NSDictionary *deviceDescription

Swift

var deviceDescription: [NSObject : AnyObject] { get }

解説

スクリーンのデバイス辞書を返します。
たとえばこのような結果が返ってきます。
NSDeviceBitsPerSample = 8;
NSDeviceColorSpaceName = NSCalibratedRGBColorSpace;
NSDeviceIsScreen = YES;


NSDeviceSize = <44800000 44400000 >;
NSScreenNumber = 69665344;

NSDeviceIsScreen
NSDeviceSize
NSScreenNumber
NSDeviceColorSpaceName
NSDeviceBitsPerSample
NSDeviceResolution = NSSize: {72, 72}

設定値

バイス辞書
Objective-C

@property(readonly, copy) NSDictionary *deviceDescription

Swift

var deviceDescription: [NSObject : AnyObject] { get }

引数

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.0

参照

更新時のバージョン

OS X 10.10.3
Swift1.2

関連記事(外部サイト)

例文

NSLog([[[NSScreen mainScreen] deviceDescription] description]);

Swift4.0

    @IBAction func function005(_ sender: Any) {
        let mainScreen : NSScreen = NSScreen.deepest!
        let dic = mainScreen.deviceDescription
        //Get keys
        print(Array(dic.keys))
        print(dic.keys.map {$0})
        
        //Get value of NSDeviceResolution
        let key = NSDeviceDescriptionKey(rawValue: "NSDeviceResolution")
        if let reso = dic[key]{
            print(reso) //-> NSSize: {72, 72}
        }
    }

Swift

//NSScreen mainScreen()
    //NSScreen deepestScreen()
    //NSScreen screens()
    //NSScreen supportedWindowDepths()
    //NSScreen deviceDescription
    @IBAction func function001(sender: AnyObject) {
        let theScreen : NSScreen = NSScreen.mainScreen()!
        NSLog("main screen size=  (%.2f✕%.2f)",
                                    Float(theScreen.frame.size.width),
                                    Float(theScreen.frame.size.height) )
        //-> main screen size=  (1366.00✕768.00)
        
        let deepestScreen : NSScreen = NSScreen.deepestScreen()!
        NSLog("deepestScreen screen depth= %d", NSBitsPerPixelFromDepth(deepestScreen.depth) )
        //-> deepestScreen screen depth= 24
        

        
        let supportedWindowDepths : UnsafePointer<NSWindowDepth> = theScreen.supportedWindowDepths
        
        NSLog("supportedWindowDepths = %d", NSBitsPerPixelFromDepth( supportedWindowDepths[0]) )
        //-> supportedWindowDepths = 8
        
        let screenArray : [AnyObject] = NSScreen.screens()!
        for value in screenArray {
            NSLog("screen size=  (%.2f✕%.2f)",
                Float(value.frame.size.width),
                Float(value.frame.size.height) )
        }
        //-> screen size=  (1366.00✕768.00)
        //-> screen size=  (1920.00✕1080.00)

        let descDic : [NSObject:AnyObject] = theScreen.deviceDescription
        NSLog("description = %@", descDic )
        
        //description = {
        //    NSDeviceBitsPerSample = 8;
        //    NSDeviceColorSpaceName = NSCalibratedRGBColorSpace;
        //    NSDeviceIsScreen = YES;
        //    NSDeviceResolution = "NSSize: {72, 72}";
        //    NSDeviceSize = "NSSize: {1366, 768}";
        //    NSScreenNumber = 69680256;
        //}
        
        
        
        var window : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: theScreen )
        windowArray.addObject(window) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        window.center()//ウインドウをスクリーンの中心に
        window.title = "ウインドウタイトル"//タイトル設定
        window.orderFront(self)//前面に
        window.makeKeyAndOrderFront(self)//表示
    }