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
Post a Comment