forked from ra1028/DifferenceKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*: | ||
## Welcome to `DifferenceKit` Playground | ||
---- | ||
> 1. Open DifferenceKit.xcworkspace. | ||
> 2. Build the DifferenceKit. | ||
> 3. Open DifferenceKit playground in project navigator. | ||
> 4. Show the live view in assistant editor. | ||
*/ | ||
import DifferenceKit | ||
import PlaygroundSupport | ||
import UIKit | ||
|
||
let viewController = TableViewController() | ||
let navigationController = UINavigationController(rootViewController: viewController) | ||
navigationController.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480) | ||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
PlaygroundPage.current.liveView = navigationController.view | ||
|
||
let source = [ | ||
Section(model: "Section 1", elements: ["A", "B", "C"]), | ||
Section(model: "Section 2", elements: ["D", "E", "F"]), | ||
Section(model: "Section 3", elements: ["G", "H", "I"]), | ||
Section(model: "Section 4", elements: ["J", "K", "L"]) | ||
] | ||
|
||
let target = [ | ||
Section(model: "Section 5", elements: ["M", "N", "O"]), | ||
Section(model: "Section 1", elements: ["A", "C"]), | ||
Section(model: "Section 4", elements: ["J", "I", "K", "L"]), | ||
Section(model: "Section 3", elements: ["G", "H", "Z"]), | ||
Section(model: "Section 6", elements: ["P", "Q", "R"]), | ||
] | ||
|
||
viewController.dataInput = source | ||
|
||
var isSourceShown = true | ||
viewController.refreshAction = { | ||
viewController.dataInput = isSourceShown ? target : source | ||
isSourceShown = !isSourceShown | ||
} |
55 changes: 55 additions & 0 deletions
55
DifferenceKit.playground/Sources/TableViewController.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,55 @@ | ||
import UIKit | ||
import DifferenceKit | ||
import DifferenceKitUI | ||
|
||
extension String: Differentiable {} | ||
|
||
public final class TableViewController: UITableViewController { | ||
public var refreshAction: (() -> Void)? | ||
|
||
public var dataInput: [Section<String, String>] { | ||
get { return data } | ||
set { | ||
let changeset = StagedChangeset(source: data, target: newValue) | ||
tableView.reload(using: changeset, with: .fade) { data in | ||
self.data = data | ||
} | ||
} | ||
} | ||
|
||
private var data = [Section<String, String>]() | ||
|
||
public init() { | ||
super.init(style: .grouped) | ||
tableView.sectionHeaderHeight = 30 | ||
tableView.sectionFooterHeight = 0 | ||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self)) | ||
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh)) | ||
} | ||
|
||
public required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
@objc private func refresh() { | ||
refreshAction?() | ||
} | ||
|
||
public override func numberOfSections(in tableView: UITableView) -> Int { | ||
return data.count | ||
} | ||
|
||
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return data[section].elements.count | ||
} | ||
|
||
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath) | ||
cell.textLabel?.text = data[indexPath.section].elements[indexPath.row] | ||
return cell | ||
} | ||
|
||
public override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | ||
return data[section].model | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' display-mode='rendered'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
DifferenceKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |