I am new to Swift and working through an online iOS development bootcamp course and the course has introduced the delegate design pattern. The course earlier demonstrated the design pattern via the use of the UITextFieldDelegate
and is now introducing an application that requests the user's location via import CoreLocation
, establishing a ViewController
as a CLLocationManagerDelegate
, and then responds to the didUpdateLocations
method.
The course suggests implementing delegate methods as extensions of the particular ViewController class. The below extensions work, but I am trying to understand the difference between the declaration of the delegate methods:
import UIKit
import CoreLocation
class myViewController: UIViewController {
[...]
}
extension myViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
[...]
return true
}
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
[...]
return true
}
[...]
}
extension myViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
[...]
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
[...]
}
}
The UITextFieldDelegate
extension has distinct method names. How is it possible for the methods required by the CLLocationManagerDelegate
protocol to both be named locationManager
?