6 Replies
      Latest reply on Jan 1, 2016 2:15 PM by Jessy
      Gargoyle Level 2 Level 2 (70 points)

        I'm trying to do this simple callback method:

         

        final class MyView: UIView {
            var onSomeAction: ((String) -> Void)!
        }
        
        final class MyViewController: UIViewController {
            let myView = MyView(frame: CGRectZero)
            override func viewDidLoad() {
                super.viewDidLoad()
                myView.onSomeAction = someFunc
            }
        
            private func someFunc(str: String) {
            }
        }
        

         

        But that's going to create a retain cycle (I believe).  I can't just mark the onSomeAction var as weak because that's a compile time error. 

         

        Do I really need to go to the level of defining a protocol for this just so I can mark it as a class protocol and then mark that callback to be a weak reference?

         

        I've gotta be missing something here.