概要
Swift3.0でUItableViewControllerの実装を試していて、
例えば
http://qiita.com/yutat93/items/1b6dfe34fa8537cf3329
を試すと、
Type 'ArticleListViewController' does not conform to protocol 'UITableViewDataSource'
なエラーが出ます。XCode 8.3.1 / Swift 3.1で確認。
func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
上の書き方を下の書き方に直すとOKです。
理由
以下のようにSwift2.0と3.0で変わっているためでした。そもそも元のサンプルはSwift2.0の書き方でした。
Swift 2.0 |
---|
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { } |
Swift 3 |
---|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { } |
参考サイト
それにしても
このエラーメッセージで直感的に原因が分かる人ってどれだけいるんでしょうか。。。