Rectangle 27 0

ios How do I make a class conform to a delegate in swift?


UITableViewDataSource
class YourClass: SuperClassIfAny, FirstProtocol, SecondProtocol {
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int

Agree, I actually spent some time trying to find why it wasn't compiling. I think this is a good thing, though, prevents you from stupid errors. It'd be cool if they added a more descriptive error, still :-P

If those are not implemented by the class conforming to the protocol, Xcode will give you a compile error (always check the protocol declaration, Cmd + Click will show you what methods you must implement).

Wish it would show a more useful error than: 'does not conform to protocol'

and

Note
Rectangle 27 0

ios How do I make a class conform to a delegate in swift?


func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell

Of key difference is that UITableView, NSIndexPath and UITableViewCell are no longer 'Implicitly Unwrapped Optionals'

Xcode 6 beta 7 changed the protocol slightly for UITableViewDataSource to match the following syntax on the two required implementations:

Note
Rectangle 27 0

ios How do I make a class conform to a delegate in swift?


func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell

Of key difference is that UITableView, NSIndexPath and UITableViewCell are no longer 'Implicitly Unwrapped Optionals'

Xcode 6 beta 7 changed the protocol slightly for UITableViewDataSource to match the following syntax on the two required implementations:

Note
Rectangle 27 0

ios How do I make a class conform to a delegate in swift?


UITableViewDataSource
class YourClass: SuperClassIfAny, FirstProtocol, SecondProtocol {
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int

Agree, I actually spent some time trying to find why it wasn't compiling. I think this is a good thing, though, prevents you from stupid errors. It'd be cool if they added a more descriptive error, still :-P

If those are not implemented by the class conforming to the protocol, Xcode will give you a compile error (always check the protocol declaration, Cmd + Click will show you what methods you must implement).

Wish it would show a more useful error than: 'does not conform to protocol'

and

Note