macOS/iOS API解説

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

目次

sendAction:to:from:

INDEX>AppKit>NSApplication

ターゲットにメッセージを送信します

Objective-C

- (BOOL)sendAction:(SEL)anAction
                to:(id)aTarget
              from:(id)sender

Swift

func sendAction(_ anAction: Selector,
             to aTarget: AnyObject?,
           from sender: AnyObject?) -> Bool

解説

ターゲット(aTarget)にメッセージ(anAction)を送信します。

返り値

Objective-C

( BOOL )

YES/NO

Swift

Bool

true/false

引数

Objective-C

( SEL )anAction

Swift

_ anAction: Selector

セレクタ

Objective-C

( id )aTarget

Swift

to aTarget: AnyObject

ターゲット

Objective-C

( id )sender

Swift

 from sender: AnyObject?

送信オブジェクト

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.0

編集時のバージョン

10.10

参照

- targetForAction:
- tryToPerform:with:
- makeWindowsPerform:inOrder:

例文

Objective-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
	[NSApp sendAction:@selector(theAction:)
				   to:self
				 from:sender
	 ];
}
-(void)theAction:(id)sender
{
	NSLog([sender className]);
}


@end

Swift

//NSApplication sendAction:to:from:
    @IBAction func function056(sender: AnyObject) {
        //共有アプリケーションインスタンスを取得
        let anApplication = MyApplication.sharedApplication()
        //このインスタンスの関数function054:を動かしてみる
        var result:Bool = NSApp.sendAction(Selector("function054:"),
            to: self, from: self)
        (Selector("function054:"), with: self )
        //結果
        if (result){
            NSLog("function056 true")
        }else{
            NSLog("function056 false")
        }
    }