Skip to content

Instantly share code, notes, and snippets.

let vc = ViewController()
PlaygroundPage.current.liveView = vc
func display(device: Device, orientation: Orientation, language: Language) {
let vc = R.storyboard.twitter.instantiateInitialViewController()!
let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc)
AppEnvironment.language = language
PlaygroundPage.current.liveView = parent
vc.load(statuses)
}
// 端末の大きさ, 向き, 言語を網羅的に指定して列挙していく
display(device: .phone3_5inch, orientation: .portrait, language: .ja)
//display(device: .phone3_5inch, orientation: .portrait, language: .en)
//display(device: .phone4inch, orientation: .portrait, language: .ja)
//display(device: .phone4inch, orientation: .portrait, language: .en)
//display(device: .phone4_7inch, orientation: .portrait, language: .ja)
//display(device: .phone4_7inch, orientation: .portrait, language: .en)
//display(device: .phone5_5inch, orientation: .portrait, language: .ja)
//display(device: .phone5_5inch, orientation: .portrait, language: .en)
//display(device: .pad, orientation: .portrait, language: .ja)
class SimpleDataSource: NSObject, UITableViewDataSource {
private var tasks: [Task] = []
func load(with tasks: [Task]) {
self.tasks = tasks
}
.
.
.
func numberOfSections(in tableView: UITableView) -> Int {
return Category.allCases.count + 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return 1
case 1:
return tasks.filter { $0.category == .personal }.count
case 2:
return tasks.filter { $0.category == .shopping }.count
case 3:
return tasks.filter { $0.category == .work }.count
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
return tableView.dequeueReusableCell(withIdentifier: "ProfileTableViewCell") as! ProfileTableViewCell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "TaskTableViewCell") as! TaskTableViewCell
let personalTask = tasks.filter { $0.category == .personal }[indexPath.row]
cell.configure(with: personalTask)
return cell
case 2:
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return nil
case 1:
return Category.personal.rawValue
case 2:
return Category.shopping.rawValue
case 3:
return Category.work.rawValue
class CommonizedDataSource: NSObject, UITableViewDataSource {
private var values: [(headerTitle: String?, rows: [(value: Any, reusableId: String)])] = []
func load(_ tasks: [Task]) {
self.values = [
(
headerTitle: nil,
rows: [(value: (), reusableId: "ProfileTableViewCell")]
),
func numberOfSections(in tableView: UITableView) -> Int {
return values.count
}