macOS/iOS API解説

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

目次

window

INDEX>AppKit>NSAlert>

アラートウインドウがついているウインドウ

解説

アラートウインドウがついているウインドウを返します。
Objective-C

@property(readonly, strong) id window

Swift

var window: AnyObject { get }

返り値

Objective-C

id

Swift

AnyObject { get }

NSPanel


オブジェクト()

引数

なし

フレームワーク

ApplicationKit

クラス

NSAlert

使用可能

10.3

編集時のバージョン

OS X 10.10

参照

例文

Objective-C

NSLog([[alert window] description]);

Swift5.1

//NSAlert icon
    @IBOutlet weak var imageView: NSImageView! //Windows image view
    @IBAction func function014(sender: AnyObject) {
        
        //End even if there are other modals.
        NSApp.abortModal()
        
        //Create NSAlert
        let alert:NSAlert = NSAlert()
        
        //Get icon image
        let anApplication = NSApplication.shared
        let imageObj:NSImage = anApplication.applicationIconImage
        
        //Make alert icon image an imageObj
        alert.icon = imageObj
        
        //1st button
        alert.addButton(withTitle: NSLocalizedString("Stop", comment:"停止"))
        //2nd button
        alert.addButton(withTitle: NSLocalizedString("Continue", comment:""))
        //Display sheet
        alert.beginSheetModal(for: self.view.window!) { responseCode in
            if NSApplication.ModalResponse.alertSecondButtonReturn == responseCode {
                //paste  when second button is pressed
                print("SecondButton")
                //Set image to  image view on window
                self.imageView.image = imageObj
            }
        }
    }

Swift

    //NSAlert window
    @IBAction func function016(sender: AnyObject) {
        NSLog("function014 called")
        //なにかモーダルがあっても終わり
        NSApp.abortModal()
        
        //テキストの作成
        let messageText:String = "Message text" as String
        let informativeText:String = "Information text" as String
        //NSAlertの作成
        let alert:NSAlert = NSAlert()
        
        let anApplication = NSApplication.sharedApplication()
        var imageObj:NSImage = anApplication.applicationIconImage
        alert.icon = imageObj
        //1つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Stop", comment:"停止"))
        //2つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Continue", comment:""))
        //シートを出す
        alert.beginSheetModalForWindow(window) { responseCode in
            if NSAlertSecondButtonReturn == responseCode {
                NSLog("SecondButton")
                self.imageView.image = imageObj
            }
        }
        NSLog("window %@",alert.window.description )
        
    }