macOS/iOS API解説

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

目次

frontmostApplication

INDEX>AppKit>NSWorkspace

最前面のアプリケーション

Objective-C

@property(readonly, strong) NSRunningApplication *frontmostApplication

Swift

var frontmostApplication: NSRunningApplication? { get }

解説

最前面のアプリケーション

設定値

Objective-C

@property(readonly, strong) NSRunningApplication *frontmostApplication

Swift

var frontmostApplication: NSRunningApplication? { get }

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.0

更新時のバージョン

OS X 10.10

参照

関連記事(外部サイト)

例文

Objective-C

Swift

    //タイマーが起動した時の実行メソッド
    func timer027(timer:NSTimer!) {
        //選択したファイルを
        let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace()
        
        NSLog("%@",(theWorkspace.frontmostApplication?.description)!)
        // -> <NSRunningApplication: 0x600000101290 (com.apple.dt.Xcode - 1148)>
        // -> <NSRunningApplication: 0x600000101290 (com.apple.dt.Xcode - 1148)>
        // -> <NSRunningApplication: 0x600000101290 (com.apple.Safari - 1549)>
        
    }
    @IBAction func function027(sender: AnyObject) {
        let anApplication = NSApplication.sharedApplication()
        //アプリケーションを隠す
        anApplication.hide(self)
        //タイマー作成
        var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("timer027:"), userInfo: nil, repeats: true )
    }