macOS/iOS API解説

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

目次

detachDrawingThread:toTarget:withObject:

INDEX>AppKit>NSApplication

新しいオートリリースプールを作って、スレッドを実行します

Objective-C

+ (void)detachDrawingThread:(SEL)selector
                   toTarget:(id)target
                 withObject:(id)argument

Swift

class func detachDrawingThread(_ selector: Selector,
                      toTarget target: AnyObject,
                    withObject argument: AnyObject?)

解説

新しいオートリリースプールを作って、スレッドを実行します。

返り値

なし

引数

Objective-C

( SEL )selector

Swift

_ selector: Selector

セレクタ

Objective-C

( id )target

Swift

toTarget target: AnyObject

ターゲット、どのクラスのメソッド

Objective-C

( id )argument

Swift

withObject argument: AnyObject?

引数となるオブジェクト

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.0

編集時のバージョン

10.10

参照

例文

Objective-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
	//サブスレッドを作って実行する
	[NSApplication detachDrawingThread:@selector(action:) toTarget:self withObject:@" sub thread"];
	//メインの方の処理
	int i;
	for (i=1;i<2000;i++) {
		NSLog(@"main thread %d",i);
    }
}

-(void)action:(id)arg
{
	//サブの方の処理
	int i;
	for (i=1;i<2000;i++) {
		NSLog(@"%@ %d",arg,i);
    }
}
@end

Swift

//NSApplication detachDrawingThread:toTarget:withObject:
    @IBAction func function054(sender: AnyObject) {
        //共有アプリケーションインスタンスを取得
        let anApplication = MyApplication.sharedApplication()
        //
        NSApplication.detachDrawingThread(Selector("methodFromFunction054:"),
            toTarget: self,
            withObject: self)
    }
    /別スレッドで動くメソッド
    func methodFromFunction054(info:AnyObject) {
        NSLog("methodFromFunction054")
    }