Home>

To learn Delegate Swift: Is Delegate too mysterious? ? ? I looked at the site called and wrote it in the same way in the editor, but an error occurred in the weak part.

The copied code is as follows.

protocol Ask {
    func goOtsukai ()
}
class Parent {
    werk var delegate: Ask! // An error occurs here
    func say () {
        print ("Take tea")
        delegate.goOtsukai ();
    }
}
class Child1: Ask {
    func goOtsukai () {
        print ("I will go")
    }
}
class Child2: Ask {
    func goOtsukai () {
        print ("Go")
    }
}
let myParent = Parent ();
let myChild1 = Child1 ();
myParent.delegate = myChild1;
myParent.say ()

We deleted the weak and compiled without any problems. What does the weakness in this code do? Do you have any problems with the deletion?