Daily iOS
Memory and ARC

Delegates and weak references

You try to declare weak var delegate: MyDelegate? and the compiler rejects it. Why, and how do you fix it?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

weak only applies to class instances, and a struct can adopt a protocol type too, so the compiler rejects it. Constrain the protocol to AnyObject to mark it class-only and it compiles.

Share a question