Why such line of code needed?

Discussion in 'iOS Programming' started by erdinc27, Mar 30, 2018.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    Hey guys. There is a project that I develop. I am the 3rd developer working on it. I have a line of code that exist almost in each method in view controllers.
    Code:
    __weak xViewController *weakSelf = self;
    why such a code needed?
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    This is sometimes know as the 'weak self strong self dance'. It is used inside objective c blocks that are executed asynchronously to prevent retain cycles. There is a ton of info on this topic online. Search for 'retain cycles weak' or similar.
     

Share This Page