如何使类符合swift中的协议?

Phi*_*lip 20 ios swift

我需要使一个类符合Swift中的协议才能实现委托.我该怎么办?

Osc*_*ros 42

class YourClass: SuperClassIfAny, FirstProtocol, SecondProtocol {
}
Run Code Online (Sandbox Code Playgroud)

但请注意,某些协议要求您实现委托方法.例如,UITableViewDataSource 要求您实施

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
Run Code Online (Sandbox Code Playgroud)

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
Run Code Online (Sandbox Code Playgroud)

如果那些不符合协议的类实现,Xcode将给你一个编译错误(总是检查协议声明,Cmd + Click将显示你必须实现的方法).