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
struct PresentationViewModel { | |
let title: String | |
let summary: String | |
let date: String | |
init(presentation: Presentation) { | |
title = presentation.title | |
summary = presentation.summary | |
date = DateFormatter.short.string(from: presentation.date) | |
} |
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
import UIKit | |
class ViewController: UIViewController { | |
override func accessibilityPerformEscape() -> Bool { | |
dismiss(animated: true) | |
return true | |
} | |
} |
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
import UIKit | |
class RatingView: UIView { | |
private(set) var value: Int = 1 | |
override var accessibilityTraits: UIAccessibilityTraits { | |
get { return .adjustable } | |
set {} | |
} |
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
class SectionHeader: UICollectionReusableView { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
accessibilityTraits.insert(.header) | |
} | |
} |
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
import UIKit | |
class BarChartView: UIView { | |
private enum Layout { | |
static let barWidth: CGFloat = 30 | |
static let maxHeightRatio: CGFloat = 0.8 | |
} | |
var values: [Double] = [] { | |
didSet { |
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
override func layoutSubviews() { | |
super.layoutSubviews() | |
guard let max = values.max() else { return } | |
subviews.forEach { $0.removeFromSuperview() } | |
var x: CGFloat = Layout.barWidth | |
let maxHeight: CGFloat = bounds.height * Layout.maxHeightRatio | |
var accessibilityElements: [UIAccessibilityElement] = [] | |
values.forEach { value in | |
let height = CGFloat(value / max) * maxHeight |
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
import UIKit | |
class StackViewController: UIViewController { | |
private let scrollView = UIScrollView() | |
private let stackView = UIStackView() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(scrollView) | |
scrollView.addSubview(stackView) |
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
import Foundation | |
import Combine | |
struct Repo: Decodable { | |
var id: Int | |
let owner: Owner | |
let name: String | |
let description: String | |
struct Owner: Decodable { |
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
import UIKit | |
import Combine | |
class ViewController: UITableViewController { | |
private let githubService: GithubService | |
private var cancellable: AnyCancellable? | |
private var repos: [Repo] = [] { | |
didSet { | |
tableView.reloadData() | |
} |
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
private func fetchRepos(matching query: String) { | |
githubService | |
.search(matching: query) | |
.replaceError(with: []) | |
.subscribe(on: DispatchQueue.global()) | |
.receive(on: OperationQueue.main) | |
.sink { repos in print("count:", repos.count) } | |
} |