PlaygroundでTable Viewを表示してみた。

[2020/12/01追記]
以下のサンプルコードをXcode12.2/Swift5.3.1で動作するのを確認しました。
[追記ここまで]

Xcode8とSwift3で、PlaygroundでViewを表示して試す仕様が変わったので試してみました。

```swift:TableView.playground
import UIKit

//****************************
// MARK: Model
//****************************
struct Album {
    let title: String
    let artist: Artist
    init(title: String, artist: Artist) {
        self.title = title
        self.artist = artist
    }
}

struct Artist {
    let name: String
}

let beatles = Artist(name: "The Beatles")

let albums = [
    Album(title: "Please Please Me", artist: beatles),
    Album(title: "With The Beatles", artist: beatles),
    Album(title: "A Hard Day's Night", artist: beatles),
    Album(title: "Beatles For Sale", artist: beatles),
    Album(title: "Help!", artist: beatles),
    Album(title: "Rubber Soul", artist: beatles),
    Album(title: "Revolver", artist: beatles),
    Album(title: "Sgt. Pepper's Lonely Hearts Club Band", artist: beatles),
    Album(title: "The Beatles", artist: beatles),
    Album(title: "Yellow Submarine", artist: beatles),
    Album(title: "Abbey Road", artist: beatles),
    Album(title: "Let it be", artist: beatles),
]

//****************************
//MARK: Table View
//****************************
final class BeatlesTableViewController: UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func tableView(_ tableView: UITableView,
                            numberOfRowsInSection section: Int) -> Int {
        return albums.count
    }
    
    override func tableView(_ tableView: UITableView,
                            heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 80.0
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView,
                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil)
        cell.textLabel?.text = albums[indexPath.row].title
        cell.detailTextLabel?.text = albums[indexPath.row].artist.name
        
        return cell
    }
}

//****************************
//MARK: Live View Configuration
//****************************

import PlaygroundSupport

// プレイグラウンドでWindowの表示

// Playgroundでの非同期処理を待つオプション
PlaygroundPage.current.needsIndefiniteExecution = true

let viewController = BeatlesTableViewController()
viewController.title = "I love Beatles."
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)

//Live Viewに上記のViewを表示させる
PlaygroundPage.current.liveView = navigationController.view

```

![SS 2017-03-13 20.02.59.png](https://qiita-image-store.s3.amazonaws.com/0/162670/2485c5f2-4fe8-8d6a-9e63-c4e98f509171.png)

#参考
- [Improving Existing Apps with Modern Best Practices](https://developer.apple.com/videos/play/wwdc2016/213/)

- [XCPlayground Module Reference](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/XCPlaygroundModuleRef/XCPlayground.html#//apple_ref/doc/uid/TP40016564)

- [XCode8でPlaygroundを使ってTableViewを表示してみる](http://blog.yayoc.com/ios/2016/08/10/use-playground-on-xcode8.html)

- [【初心者向け】Swift3で爆速コーディングその１(画面作成とSnippetsの使い方)](http://qiita.com/teradonburi/items/d0ffb6367e34966d761b)

- [Xcode 7のPlaygroundで出来ることまとめ](http://qiita.com/mono0926/items/9f8324637d1dca1e7075)