finishLaunching
解説
起動した後に呼び出されます。
NSApplicationのサブクラスで使用します。
このメソッド(関数)をオーバーライドする場合には、スーパークラスを呼びださなければいけません。
このメソッド(関数)を開始するときにデフォルトの通知センターにNSApplicationWillFinishLaunchingNotificationをポストします。
このメソッド(関数)を終了するときにデフォルトの通知センターにNSApplicationDidFinishLaunchingNotificationをポストします。
オーバーライドした時には「アプリケーション設定」の「Cocoa固有の設定」をNSApplicationから、サブクラス(たとえばMyApplication)に変更しないといけません
Info.plistのNSPrincipalClassキーの値を(たとえば)MyApplicationにします。
<key>NSPrincipalClass</key> <string>MyApplication</string>
Swiftの場合、@objc(MyApplication)を使う
import AppKit @objc(MyApplication) class MyApplication: NSApplication { }
返り値
( void )
なし
引数
なし
フレームワーク
ApplicationKit
クラス
NSApplication
Instance Methods
使用可能
10.0
更新時のバージョン
10.10
関連記事
SwiftでNSApplicationのサブクラスを使う場合
Subclass NSApplication in Swift - Stack Overflow
Using Swift with Cocoa and Objective-C: Writing Swift Classes with Objective-C Behavior
例文
#import "MyApplication.h" @implementation MyApplication -(void)finishLaunching { //デフォルトの通知センターをnCenterに NSNotificationCenter *nCenter =[NSNotificationCenter defaultCenter]; //nCenterにオブザーバーを加える [nCenter addObserver:self selector:@selector(applicationWillLaunchNotify:) //呼び出されるメソッド name:@"NSApplicationWillFinishLaunchingNotification" //ウインドウがリサイズされたら object:nil]; //nCenterにオブザーバーを加える [nCenter addObserver:self selector:@selector(applicationDidLaunchNotify:) //呼び出されるメソッド name:@"NSApplicationDidFinishLaunchingNotification" //ウインドウがリサイズされたら object:nil]; //隠す NSLog(@"finishLaunching"); [super finishLaunching]; } //NSApplicationWillFinishLaunchingNotificationが通知されたときのメソッド - (void)applicationWillLaunchNotify:(NSNotification *)notification { NSLog(@"recive NSApplicationWillFinishLaunchingNotification"); } //NSApplicationDidFinishLaunchingNotificationが通知されたときのメソッド - (void)applicationDidLaunchNotify:(NSNotification *)notification { NSLog(@"recive NSApplicationDidFinishLaunchingNotification"); } @end
import AppKit @objc(MyApplication) class MyApplication: NSApplication { override func finishLaunching(){ super.finishLaunching() NSLog("finishLaunching") } }