Objective-C method ':' provided by method ' ' conflicts with optional requirement method ' ' in protocol
I have the following code func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) -> [Int] and I want to return an array of Int from that method, but I am getting this error
Objective-C method 'tableView:didDeselectRowAtIndexPath:' provided by method 'tableView(:didDeselectRowAtIndexPath:)' conflicts with optional requirement method 'tableView(:didDeselectRowAtIndexPath:)' in protocol 'UITableViewDelegate'
I have tried putting an exclamation mark after Int like so -> [Int]! but it didn't fix the error. What am I doing wrong here? Thanks.
Your class seems to implement UITableViewDelegate. The interface UITableViewDelegate does not have a return value for tableView:didDeselectRowAtIndexPath: and since your method defines a return type, there is a conflict.
If you remove the return value, so in your case [Int], it should work. You cannot define multiple methods with the same signature, but with different return values. The signature (method name + parameter) needs to be unique, so you could define methods with the same name and different parameters, but not methods with the same name/parameters and different return types.