macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

canRepresent

INDEX>AppKit>NSScreen

スクリーンでサポートされる色深度を返します

Swift

open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool

解説

ガモットマッピング可能かどうかを返します。

返り値

色深度の配列
Swift

open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool

引数

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.12

参照

更新時のバージョン

OS X 10.14.5
Swift4.0

関連記事(外部サイト)

developer.apple.com


例文


Swift4.0

@IBAction func function008(_ sender: Any) {
        let screenArray : [AnyObject] = NSScreen.screens
        for value in screenArray {
            let result : Bool = value.canRepresent(.sRGB)
            if (result){
                print("YES")
            }else{
                print("NO")
            }
        }
    }

name

INDEX>AppKit>NSAppearance

アピアランス

Objective-C

@property(readonly, copy) NSString *name

Swift

var name: String { get }

解説

アピアランスの名前(読み込みのみ)

設定値

Objective-C

@property(readonly, copy) NSString *name

Swift

var name: String { get }

フレームワーク

ApplicationKit

クラス

NSAppearance

使用可能

10.9-

更新時のバージョン

OS X 10.11

参照

関連記事

例文

    //NSAppearance initWithAppearanceNamed:bundle:
    //http://cocoaapi.hatenablog.com/entry/Appkit/NSAppearance/initWithAppearanceNamed_bundle_
    //NSAppearance name
    //
    @IBAction func function001( sender: AnyObject) {
        //アピアランスの変更
        let ap : NSAppearance = NSAppearance(named: NSAppearanceNameVibrantDark)!
        NSLog("name = %@",ap.name)
        //->name = NSAppearanceNameVibrantDark
        let aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            `defer`: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.appearance = ap
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        //
        let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("buttonAction001:")
        theButton.target = self
        theButton.setButtonType(.MomentaryLightButton)
        //.SwitchButton
        //.PushOnPushOffButton
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
        
    }

initWithAppearanceNamed:bundle:

INDEX>AppKit>NSAppearance

バンドルと名前でNSAppearanceオブジェクトのインスタンスを初期化して返します

Objective-C

- (instancetype)initWithAppearanceNamed:(NSString *)name
                                 bundle:(NSBundle *)bundle

Swift

init?(appearanceNamed name: String,
               bundle bundle: NSBundle?)

解説

指定のバンドルで指定された名前のアピアランスからNSAppearanceオブジェクトのインスタンスを初期化して返します。

返り値

初期化されたオブジェクト。
エラーが発生すればnil
Objective-C

instancetype

NSAppearance

Swift

NSAppearance 

引数

【name】
アピアランスファイル名
Objective-C

(NSString *)name

Swift

name: String,

【bundle】
アピアランスファイルが含まれるバンドル
Objective-C

(NSBundle *)bundle

Swift

bundle: NSBundle?

フレームワーク

ApplicationKit

クラス

NSAppearance

使用可能

10.9-

更新時のバージョン

OS X 10.11

参照

関連記事

例文

Objective-C

Swift
f:id:jjj777:20151103144730p:plain

    //NSAppearance initWithAppearanceNamed:bundle:
    //http://cocoaapi.hatenablog.com/entry/Appkit/NSAppearance/initWithAppearanceNamed_bundle_
    @IBAction func function001( sender: AnyObject) {
        //アピアランスの変更
        let ap : NSAppearance = NSAppearance(named: NSAppearanceNameVibrantDark)!
        
        let aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            `defer`: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.appearance = ap
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        //
        let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("buttonAction001:")
        theButton.target = self
        theButton.setButtonType(.MomentaryLightButton)
        //.SwitchButton
        //.PushOnPushOffButton
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
        
    }

NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification

INDEX>AppKit>NSWorkspace

アクセシビリティの表示が変更になった場合の通知

解説

おそらくVoiceOverをONにした場合に送られる通知だっと思うが、通知が帰ってくる条件がわからず詳細不明です。

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.10-

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

関連記事(外部サイト)

NSWorkspaceDidTerminateApplicationNotification

INDEX>AppKit>NSWorkspace

アプリケーションが終了するときにポストされる

解説

アプリケーションが終了するときにポストされる

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.0

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

関連記事(外部サイト)

例文

Objective-C

Swift

    //NSWorkspace NSWorkspaceDidTerminateApplicationNotification
    //アプリケーションが終了しようとするとき
    var switch049 : Bool = false
    func notifyNSWorkspaceDidTerminateApplicationNotification(notify:NSNotification) {
        //NSLog("%@",notify.description)

        let bundleID : String = (notify.userInfo! as Dictionary)["NSApplicationBundleIdentifier"]! as! String
        NSLog("Bundle ID = %@",bundleID)
        // -> Bundle ID = com.apple.mail
        
        let appName : String = (notify.userInfo! as Dictionary)["NSApplicationName"]! as! String
        NSLog("application name = %@",appName)
        // -> application name = メール
        
        let appPathe : String = (notify.userInfo! as Dictionary)["NSApplicationPath"]! as! String
        NSLog("application path = %@",appPathe)
        // -> application path = /Applications/Mail.app
        
        let appProcessID : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessIdentifier"]! as! NSNumber
        NSLog("process id = %d",appProcessID.integerValue)
        // -> process id = 36580
        
        let appProcessSerialNumberHigh : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberHigh"]! as! NSNumber
        NSLog("process serial number high = %d",appProcessSerialNumberHigh.integerValue)
        // ->process serial number high = 0
        
        let appProcessSerialNumberLow : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberLow"]! as! NSNumber
        NSLog("process serial number low = %d",appProcessSerialNumberLow.integerValue)
        // ->process serial number low = 5145832
        
        
        let runningApp : NSRunningApplication = (notify.userInfo! as Dictionary)["NSWorkspaceApplicationKey"]! as! NSRunningApplication
        NSLog("runningApp = %@",runningApp.description)
        // ->runningApp = <NSRunningApplication: 0x600000105340 (com.apple.mail - 36867)>
        NSLog("runningApp = %@",runningApp.launchDate!.description)
        // ->runningApp = 2015-04-29 09:18:27 +0000
        
        let exitStatus : NSNumber = (notify.userInfo! as Dictionary)["NSWorkspaceExitStatusKey"]! as! NSNumber
        NSLog("exit status = %d",appProcessSerialNumberHigh.integerValue)
        // ->exit status = = 0
        
        
    }

convertRectToBacking:

INDEX>AppKit>NSScreen

バイスピクセルとディスプレイの座標システムとの変換

Objective-C

- (NSRect)convertRectToBacking:(NSRect)aRect

Swift

func convertRectToBacking(_ aRect: NSRect) -> NSRect

解説

バイスピクセルとディスプレイの座標システムとの変換

返り値

Objective-C

NSRect

Swift

NSRect

引数

Objective-C

(NSRect)aRect

Swift

(_ rect: NSRect)

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.7-

更新時のバージョン

OS X 10.14.5
SWIFT4.0

参照

関連記事(外部サイト)

例文

Objective-C

Swift4.0

    @IBAction func function010(_ sender: Any) {
        let screenArray : [NSScreen] = NSScreen.screens
        for value in screenArray {
            let rect : NSRect = value.convertRectToBacking(NSMakeRect(0.0, 0.0,100.0, 100.0))
            print("rect = (\(rect.origin.x) ,\(rect.origin.y)(\(rect.size.width),\(rect.size.height)))")
            }
        //rect = (0.0 ,0.0(100.0,100.0))  //<- Normal Display
        //rect = (0.0 ,0.0(200.0,200.0))  //<- MacBooK retina Display
        //rect = (0.0 ,0.0(100.0,100.0))  //<- Normal Display
    }


Swift

    //NSScreen convertRectToBacking
    @IBAction func function006(sender: AnyObject) {
        let theScreen : NSScreen = NSScreen.mainScreen()!
        let newRect : NSRect = theScreen.convertRectToBacking(NSMakeRect(0.3, 0.0, 100.3, 123.5))
        NSLog("newRect = (x=%.2f,y=%.2f,w=%.2f,h=%.2f)",
            Float(newRect.origin.x),
            Float(newRect.origin.y),
            Float(newRect.size.width),
            Float(newRect.size.height) )
        //通常ディスプレイの場合(倍率1.0) -> newRect = (x=0.30,y=0.00,w=100.30,h=123.50)

    }