This file contains hidden or 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
| // 1 | |
| let tagCloudView = TagCloudView() | |
| let items = ["This", "is", "a", "test"] | |
| .map(TagCloudItemViewModel.init(title:)) | |
| tagCloudView.addItems(items: items) | |
| // 2 | |
| class Delegate: TagCloudViewDelegate { | |
| func removeClicked(title: String) { | |
| print("Clicked remove button on tag \(title)") |
This file contains hidden or 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
| // 1 | |
| var timer: Timer? | |
| override func viewWillStartLiveResize() { | |
| super.viewWillStartLiveResize() | |
| startTimer() | |
| } | |
| // 2 | |
| func startTimer() { | |
| let repeatedTimer = Timer.scheduledTimer( |
This file contains hidden or 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
| private func showRows() { | |
| for row in rows { | |
| rowStackView.addArrangedSubview(row) | |
| } | |
| } |
This file contains hidden or 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
| private func setupRows() { | |
| // 1: Loop over items. | |
| for item in itemViews { | |
| guard let currentRow = rows.last else { return } | |
| // 2: Check whether to extend current row or start a new row. | |
| let currentRowWidth = currentRow.arrangedSubviews | |
| .map(\.frame.width) | |
| .reduce(0, +) |
This file contains hidden or 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
| private func clearRows() { | |
| for row in rows { | |
| rowStackView.removeArrangedSubview(row) | |
| row.removeFromSuperview() | |
| } | |
| rows = [emptyRowStackView] | |
| } |
This file contains hidden or 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
| // 1 | |
| private var itemViews = [TagCloudItemView]() | |
| private var rows = [NSStackView]() | |
| private var rowStackView = NSStackView() | |
| private var emptyRowStackView = NSStackView() | |
| /* Configure and style these views... */ | |
| // 2 | |
| func buildRows() { | |
| clearRows() |
This file contains hidden or 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
| dependencies: [ | |
| // ... | |
| .package(url: "https://github.com/jpsim/SourceKitten", from: "0.27.0") | |
| ] |
This file contains hidden or 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
| // 1 | |
| import SourceKittenFramework | |
| // 2 | |
| let file = File(path: "/path/to/sourcefile.swift")! | |
| // 3 | |
| let code = """ | |
| import UIKit |
This file contains hidden or 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
| // 1 | |
| func syntaxStructure(from file: File) -> SyntaxStructure? { | |
| do { | |
| // 2 | |
| let structure = try Structure(file: file) | |
| let jsonData = structure.description.data(using: .utf8)! | |
| // 3 | |
| return try JSONDecoder().decode(SyntaxStructure.self, from: jsonData) | |
This file contains hidden or 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
| struct SyntaxStructure: Codable { | |
| // 1 | |
| let accessibility: String? | |
| let attribute: String? | |
| let attributes: [SyntaxStructure]? | |
| let bodylength: Int? | |
| let bodyoffset: Int? | |
| let diagnosticstage: String? | |
| let elements: [SyntaxStructure]? |