macOS/iOS API解説

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

目次

delegate

INDEX>AppKit>NSAlert>

デリゲートオブジェクト
@property(assign) id<NSAlertDelegate> delegate
unowned(unsafe) var delegate: NSAlertDelegate?

解説

デリゲートオブジェクト
リモートオブジェクトの場合はnil

設定値

id<NSAlertDelegate>
NSAlertDelegate?

オブジェクト()

フレームワーク

ApplicationKit

クラス

NSAlert

使用可能

10.3

編集時のバージョン

OS X 10.10.3
Swift 1.2

参照

-setDelegate:
-alertShowHelp:

例文

NSLog([[alert delegate] description]);
    //NSAlert delegate
    @IBAction func function008(sender: AnyObject) {
        //なにかモーダルがあっても終わり
        NSApp.abortModal()
        
        //テキストの作成
        let messageText:String = "Message text" as String
        let informativeText:String = "Information text" as String
        //NSAlertの作成
        let alert:NSAlert = NSAlert()
        alert.alertStyle = .WarningAlertStyle
        alert.messageText = messageText
        alert.informativeText = informativeText
        alert.delegate = self
        var delegateObj  = alert.delegate//Swift 1.2
        //var delegateObj  = alert.delegate?
        if (delegateObj != nil) {
            if (delegateObj!.conformsToProtocol(NSAlertDelegate)) {
                NSLog("YES")
            }else{
                NSLog("NO")
            }
        }else{
            NSLog("nil")
        }
        let response:Int = alert.runModal()
        
    }