-
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.
- Loading branch information
1 parent
e5d49a1
commit 1533ede
Showing
25 changed files
with
634 additions
and
502 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
Large diffs are not rendered by default.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
Playground-iOS.playground/Pages/Trees.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,62 @@ | ||
//: [Previous](@previous) | ||
|
||
import Foundation | ||
import UIKit | ||
import Bond | ||
|
||
// Tree node is a tree with a single root | ||
|
||
var t = TreeNode("Child 00", [ | ||
TreeNode("Child 000"), | ||
TreeNode("Child 001", [ | ||
TreeNode("Child 0010") | ||
]), | ||
TreeNode("Child 002", [ | ||
TreeNode("Child 0020", [ | ||
TreeNode("Child 00200") | ||
]), | ||
TreeNode("Child 0021") | ||
]) | ||
]) | ||
|
||
print(t.dfsView.map { $0.value }) | ||
print(t.bfsView.map { $0.value }) | ||
|
||
print(t.dfsView.firstIndex(where: { $0.value.hasSuffix("200") })!) | ||
print(t.dfsView.allSatisfy { $0.value.starts(with: "Child") }) | ||
print(t.dfsView.randomElement()!) | ||
|
||
// Tree node is a tree with multiple roots | ||
|
||
var ta = TreeArray<String>([ | ||
t, | ||
TreeNode("Child 01", [ | ||
TreeNode("Child 010") | ||
]) | ||
]) | ||
|
||
print(ta.dfsView.map { $0.value }) | ||
print(ta.bfsView.map { $0.value }) | ||
|
||
print(ta.dfsView.firstIndex(where: { $0.value.hasSuffix("200") })!) | ||
print(t.dfsView.allSatisfy { $0.value.starts(with: "Child") }) | ||
print(t.dfsView.randomElement()!) | ||
|
||
// Custom trees | ||
|
||
extension UIView: TreeProtocol { | ||
|
||
public var children: [UIView] { | ||
return subviews | ||
} | ||
} | ||
|
||
let v = UIPickerView() | ||
|
||
print(v.dfsView.map { type(of: $0) }) | ||
print(v.bfsView.map { type(of: $0) }) | ||
|
||
print(v[childAt: [0, 0]]) | ||
|
||
|
||
//: [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
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.