delegate:委托,代理
类中有属性,方法,事件
delegate与事件有关
protocol:协议,与类相似,但是其中属性,方法,事件没有具体内容
当class遵守协议之后,需要实现这个协议中的某一些函数。
delegate的使用
例如在获取地址的方法里
import CoreLocation
class ViewController: UIViewController,CLLocationMangerDelegate {
//加入delegate
let locationManager = CLLocationManager()
//引入需要使用的方法,locationManager为CLLocationManager()的实例
override func viewDidLoad() {
super.viewDidLoad