「SwiftらしいTable View Controller」のコードが動かなかったので...
Swiftのバージョン
$ swift --version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
import UIKit
struct Person{
let name : String
}
let people = [
Person(name:"たもり"),
Person(name:"さんま"),
Person(name:"たけし"),
]
final class MyTableViewController: UITableViewController {
let items :[Person]
init(items :[Person], style: UITableViewStyle) {
self.items=items
super.init(style:style)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=UITableViewCell(style:.default,reuseIdentifier:nil)
let item=items[indexPath.row]
cell.textLabel?.text=item.name
return cell
}
}
let tableVC = MyTableViewController(items:people,style:.plain)
import PlaygroundSupport
PlaygroundPage.current.liveView = tableVC
PlaygroundPage.current.needsIndefiniteExecution = true
ポイント
- PG用の使用モジュールが変更。
- 旧>
import XCPlayground
- 新>
import PlaygroundSupport
- 旧>
- overrideメソッド名が変更。
- 旧>
cellForRowAtIndexPath
- 新>
cellForRowAt
- 旧>
- 定数値が小文字に変更。
- 旧>
.Plain
、.Default
- 新>
.plain
、.default
- 旧>