ios - Invoke block immediately after definition -


i have code this:

void (^testblock)() = ^ {     nslog(@"test"); }; testblock(); 

can invoke block after definition like:

void (^testblock)() = ^ {     nslog(@"test"); }(); 

this's way when block invoked once. ideas?

when call void (^testblock)() = ^ {...}(); try keep reference whatever block returns, not block itself. xcode throws:

initializing 'void(^__strong)()' expression of incompatible type 'void'. 

in other words - block returns nothing (void), , trying hold strong reference of type void(^)(), block type.

assuming want reference block, must first declare block, , call through name gave reference it, showed in first snippet.

if on other hand, wish declare block , invoke once without holding it, can drop reference it, , call:

^{     nslog(@"test"); }(); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -