LoginSignup
1
2

More than 5 years have passed since last update.

[xcode][swift 3.0]Type 'ほげほげ' does not conform to protocol 'UITableViewDataSource' なエラーが出る対策

Last updated at Posted at 2017-04-14

概要

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 { }

参考サイト

それにしても

このエラーメッセージで直感的に原因が分かる人ってどれだけいるんでしょうか。。。

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2