2014-02-06 23 views
0

我需要使用http請求的結果執行重複任務,因此想要將完成hander的聲明存儲在變量中(或者以某種方式將其聲明爲函數可以通過)。變量iOS中的存儲完成處理程序(目標c)

示例代碼:

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
    // carry out some action 
}]; 

我想能夠寫

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler: standardHandler ]; 

standardHandler含有嵌段功能。

這可能嗎?

我對Objective C非常陌生,所以很抱歉,如果這是一個明顯的問題。

回答

5

肯定的:

void (^completionHandler)(NSURLResponse *, NSData *, NSError *) = ^(NSURLResponse *response, NSData *data, NSError *error) { 
    // carry out some action 
}; 
[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:completionHandler]; 
+1

我喜歡的網站的網址! :)感謝您的信息,我會盡快接受答案! –

相關問題