macOS/iOS API解説

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

目次

shared

INDEX>AppKit>NSApplication

共有アプリケーションオブジェクトを返します

解説

アプリケーションを返します。まだ存在しなければ、つくって返します。グローバル変数NSAppも同様。NSApplicationインスタンスグローバル変数NSApp)を返します。
Objective-C

+ (NSApplication *)sharedApplication

Swift

open class var shared: NSApplication { get }

返り値

( NSApplication * )

共有アプリケーションオブジェクト

引数

なし

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.0-

更新時のバージョン

0S X 10.14.5
Swift4.2

例文

Objective-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
	
	[[NSApplication sharedApplication] orderFrontStandardAboutPanel:nil];
	
}

- (void)applicationWillUpdate:(NSNotification *)aNotification
{
	NSLog(@"applicationWillUpdate");
}
@end


Swift4.2

    //NSApplication.shared
    func function001()  {
        let anApplication = NSApplication.shared
        print("Shared Application Object: \(anApplication).")
    }

Swift

    func function001()  {
        
        let anApplication = NSApplication.sharedApplication()
        
        NSLog("Shared Application Object: \(anApplication).")
        
    }