2013-09-30 34 views
-1
-(void) vPerformBlockOnAllAutoCompleteHandler:((^)(BGMotherofAutoCompleteHandler * acHandler))block 
{ 
    for (BGMotherofAutoCompleteHandler * acHandler in [self arBGKeywordAutoCompleteHandlers]) { 
     block(acHandler); 
    } 
} 

好的,所以block是一個以BGMotherofAutoCompleteHandler作爲參數的塊。我通過循環和調用塊(acHandler)。這個塊的格式化代碼有什麼問題?

怎麼了?

錯誤是: /business/Dropbox/badgers/BadgerNew/BGSearchController3.m:218:49:預期的類型。在我看來,我必須在該塊之前添加空白。

所以不過,我並不需要,如果塊不要求參數添加了這一空白這部作品

-(void) vPerformBlockOnAllAutoCompleteHandler1:(void (^)(BGMotherofAutoCompleteHandler * acHandler))block 
{ 
    for (BGMotherofAutoCompleteHandler * acHandler in [self arBGKeywordAutoCompleteHandlers]) { 
     block(acHandler); 
    } 
} 

。我發現這很奇怪。

+3

誰說什麼是錯呢?編譯器?如果是這樣,告訴我們它呻吟的是什麼。 – trojanfoe

+1

是的,發佈錯誤。另外,什麼是BGMotherofAutoCompleteHandler?告訴我們'typedef'。如果它是一個塊,那麼你可能不希望'*'在那裏。 – ipmcc

回答

2

的語法是:

- (void)vPerformBlockOnAllAutoCompleteHandler:(void(^)(BGMotherofAutoCompleteHandler*))block 
{ 
for (BGMotherofAutoCompleteHandler * at in [self arBGKeywordAutoCompleteHandlers]) { 
    block(at); 
} 
} 

Here's a cheat sheet.

+0

有趣。如果塊包含參數,我必須添加void,但如果塊不需要參數,則不需要太多。 –