4 Replies
      Latest reply: Dec 27, 2016 1:58 PM by Gargoyle RSS
      Gargoyle Level 2 Level 2 (50 points)

        In view controller A I have things like a UITableView, UISearchController, and the UINavigationController.

        I also have an NSObject subclass for my delegates that needs to know about those three items, and then I assign that NSObject as the data source and delegate on the table view and he searchResultsUpdater on the search controller.

         

        If I store those as a 'let' variable in the NSObject subclass, have I created a retain cycle?  I'm wondering if I need to store them as weak vars instead.

        • Re: Should vars be weak
          eskimo Apple Staff Apple Staff (6,470 points)

          If I store those as a 'let' variable in the NSObject subclass, have I created a retain cycle?

          No.  As you’ve described it the only cycle is between your NSObject subclass and the UITableView (and friends) via its delegate reference.  However, that delegate reference is already weak.

          Honestly, though, I wouldn’t take my word for it; rather, construct the layout you want and test whether you have a retain cycle.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"