-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some improvements and new playgorunds
- Loading branch information
1 parent
c572f73
commit 6b75ec0
Showing
17 changed files
with
238 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
56 changes: 56 additions & 0 deletions
56
...ground-iOS.playground/Pages/UITableView+ObservableArray2D.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//: [Previous](@previous) | ||
|
||
import Foundation | ||
import PlaygroundSupport | ||
import UIKit | ||
import Bond | ||
import ReactiveKit | ||
|
||
let tableView = UITableView() | ||
tableView.frame.size = CGSize(width: 300, height: 600) | ||
|
||
// Note: Open the assistant editor to see the table view | ||
PlaygroundPage.current.liveView = tableView | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
// Using custom binder to provide table view header titles | ||
class CustomBinder<Changeset: SectionedDataSourceChangeset>: TableViewBinderDataSource<Changeset> where Changeset.Collection == Array2D<String, Int> { | ||
|
||
@objc func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | ||
return changeset?.collection[sectionAt: section] | ||
} | ||
} | ||
|
||
// Array2D is generic over section metadata `Section` and item value `Item`. | ||
// Section metadata is the data associated with the section, like section header titles. | ||
// You can specialise `Section` to `Void` if there is no section metadata. | ||
// Item values are values displayed by the table view cells. | ||
let initialData = Array2D<String, Int>(sectionsWithItems: [ | ||
("A", [1, 2]), | ||
("B", [10, 20]) | ||
]) | ||
|
||
let data = MutableObservableArray2D(initialData) | ||
|
||
data.bind(to: tableView, cellType: UITableViewCell.self, using: CustomBinder()) { (cell, item) in | ||
cell.textLabel?.text = "\(item)" | ||
} | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { | ||
data.appendItem(3, toSectionAt: 0) | ||
} | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
data.batchUpdate { (data) in | ||
data.appendItem(4, toSectionAt: 0) | ||
data.insert(section: "Aa", at: 1) | ||
data.appendItem(100, toSectionAt: 1) | ||
data.insert(item: 50, at: IndexPath(item: 0, section: 1)) | ||
} | ||
} | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { | ||
data.moveItem(from: IndexPath(item: 0, section: 1), to: IndexPath(item: 0, section: 0)) | ||
} | ||
|
||
//: [Next](@next) |
34 changes: 34 additions & 0 deletions
34
Playground-iOS.playground/Pages/UITableView+Signal+Diff.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//: [Previous](@previous) | ||
|
||
import Foundation | ||
import PlaygroundSupport | ||
import UIKit | ||
import Bond | ||
import ReactiveKit | ||
|
||
let tableView = UITableView() | ||
tableView.frame.size = CGSize(width: 300, height: 300) | ||
|
||
// Note: Open the assistant editor to see the table view | ||
PlaygroundPage.current.liveView = tableView | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
// A signal that emits a value every 1 second | ||
let pulse = SafeSignal<Int>.interval(1) | ||
|
||
// A signal of [String] | ||
let data = SafeSignal | ||
.sequence([ | ||
["A"], | ||
["A", "B", "C"], | ||
["A", "C"], | ||
["C", "A"] | ||
]) | ||
.zip(with: pulse) { data, _ in data } // add 1 second delay between events | ||
.diff() // diff each new array against the previous one | ||
|
||
data.bind(to: tableView, cellType: UITableViewCell.self) { (cell, string) in | ||
cell.textLabel?.text = string | ||
} | ||
|
||
//: [Next](@next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.