After reading some posts here regarding this issue, I discovered that my protocol should inherit from 'class' in order for 'weak' to work on my delegate variable.
'weak' may only be applied to class or class-bound protocol types.
If my protocol does not inherit from 'class', does swift 'infer' that it should be weak?
Is this the de facto way for casting a variable of type 'protocol' to weak ?
What happens in terms of memory management
protocol FacebookLoginViewControllerDelegate: class {
func facebookLoginViewControllerDidLogin(controller: FacebookLoginViewController)
}
class FacebookLoginViewController: UIViewController {
weak var delegate: FacebookLoginViewControllerDelegate?
}
: class
) simply tells the compiler that it can only ever represent a reference type – and therefore you can useweak
on it. You cannot make a value typeweak
, as ARC (automatic reference counting) works with references, not with values. – Hamish