Reputation: 1980
I have 'helper' singleton class that needs to pop up a login, if a login is required. I want to capture the return from the login view controller, so I have implemented a protocol in my LoginViewController, and need to set my delegate in the singleton class, but when I attempt to do:
loginController.delegate = self
Xcode tries to correct it as:
loginController.delegate = self as! LoginViewControllerDelegate
The protocol in my LoginViewController.swift file:
protocol LoginViewControllerDelegate {
func loginViewControllerDidReturn(identifier: String)
}
Any ideas?
Upvotes: 1
Views: 103
Reputation: 1542
Make sure your LoginViewController definition is :
class LoginViewController: UIViewController, LoginViewControllerDelegate {
...
}
This inform the compiler that your class implement the protocol.
You can also make an extension implementing the protocol :
extension LoginViewController: LoginViewControllerDelegate {
// Implement here the func of your protocol
}
Upvotes: 3
Reputation: 3777
Does 'self' conform to the LoginViewControllerDelegate protocol?
Upvotes: 1