macOS/iOS API解説

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

目次

delegate

INDEX>AppKit>NSApplication

アプリケーションのデリゲートを返します

Objective-C

@property(assign) id< NSApplicationDelegate > delegate

Swift

weak open var delegate: NSApplicationDelegate?

解説

アプリケーションのデリゲートを返します。

返り値

Swift

NSApplicationDelegate?

Objective-C

( id )

デリゲートオブジェクト

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.0

更新時のバージョン

0S X 10.14.5
Swift4.2

参照

例文

Objective-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
	id aDelegate = [NSApp delegate];
	NSLog([aDelegate className]);
	NSLog([aDelegate description]);
	
}

- (void)applicationDidHide:(NSNotification *)aNotification
{
	[info setStringValue:@"applicationDidHide"];
}
@end

Swift4.2

    //NSApplication delegate
    func function002()  {
        
        let anApplication = NSApplication.shared
        let obj = anApplication.delegate
        print("Delegate Object: \(String(describing: obj)).")
        
    }


Swift

//NSApplication delegate
    func function002()  {
        
        let anApplication = NSApplication.sharedApplication()
        let obj = anApplication.delegate
        NSLog("Delegate Object: \(obj).")
        
    }