Monday, 15 August 2011

ios - Do I need a strongSelf in block to keep self alive and does the strongSelf really work? -


itemprop = "text">

This is what I learned: when using self block maintained

  1. To break the need for a weakSelf need cycle
  2. I have a strongSelf self We need to stop it from becoming zero half-way

So I want to test if any strong self actually self If you are alive:

  @implementation ViewController - (zero) viewDidoad {{Su But viewdload]; NSLog (@ "viewDidLoad"); Self.test = @ "" test "; NSLog (@"% @ ", self.test); __vek type (self) weak Self = self; dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^ {__strong typeof (weakSelf) strongSelf = weakSelf; strongSelf.test = @ "newTest"; NSLog (@ "% @", strongSelf. tests);});} - (void) {Delok Anselog (@ " Delok ");} @ end  

View controller will be pushed into a navigation controller and the output will immediately pop out

Why is it null?

Another question is, I have a project In indicating block are weak themselves strongSelf tones without me enough to indicate 11 accident related? To add worth it strongSelf For each of them?

strong self ensures that If self has not yet been released, it will not be during block execution.

If you strongSelf , it will not be equal to

You should check if strongSelf can do is:.

  dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^ {typeof (weakSelf) strongSelf = if weakSelf; not // need __strong (strongSelf ) {StrongSelf.test = @ "newTest"; NSLog (@ "% @", Strong Sol.Test);}}});  

No comments:

Post a Comment