ios - How can I retain a local variable that is set in a block? -


so have:

@interface testappcontrol : nsobject {     nsstring *s; } 

and in block want do

[sendapi setgroupwithname:groupname completionhandler:^(nsarray *errors) {     s = @"something"; }];  nslog(@"%@", s); //<--- s null 

so want keep value "something" after leave block. possible arc?

declare __block variable, can use outside block , alter inside block.

__block nsstring *s = nil;  void(^block)(void) = ^ {     s = @"something"; }; block(); nslog(@"%@", s);  s = @"blah"; nslog(@"%@", s);  block(); nslog(@"%@", s); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -