Skip to content

Instantly share code, notes, and snippets.

View pattogato's full-sized avatar

Bence Pattogato pattogato

View GitHub Profile
@pattogato
pattogato / add-money-migration.swift
Created February 22, 2024 09:39
iOS add money migration missing info
// webapp /payments and /paymentOptions returns account details
// we use this to show bank transfer info
let type: BankType
let title: String?
let description: DescriptionResponse?
let summaries: [SummaryItemResponse]
let details: [DetailsItemResponse]
let alert: AlertResponse?
let shareText: String?
struct Step {
enum StepFlowResult {
case finished
case dismissed
}
enum Presentable {
case viewController(UIViewController, delegate: HasUSBalanceInterestActivationFlowStepDelegate)
case flow(any Flow<StepFlowResult>)
}
final class WeatherPresenterImpl {
var selectedDay: DailyEntry
private let days: [DailyEntry]
private weak var view: WeatherView?
// 1.
func selectDay(_ day: WeatherViewModel.Day) {
guard let selectedDayModel = days.first(where: { $0.id == day.id }) else {
return
}
@pattogato
pattogato / VC.swift
Last active September 8, 2021 12:39
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard
let item = dataSource.itemIdentifier(for: indexPath),
case let WeatherViewModel.Item.day(day) = item
else { return }
presenter.selectDay(day)
}
struct DailyEntry {
let name: String
let icon: WeatherIcon
let minTemp: String
let maxTemp: String
let hours: [HourlyEntry]
let id: UUID
}
struct HourlyEntry {
struct WeatherViewModel {
enum Item: Hashable {
case day(Day)
case hour(Hour)
}
var sections: [Section: [Item]]
let title: String
}
struct WeatherViewModel {
struct Day: Hashable {
let name: String
let icon: WeatherIcon
let minTemp: String
let maxTemp: String
let selected: Bool
let id: UUID
}
struct Hour: Hashable {
extension WeatherViewModel {
mutating func select(dailyEntry: DailyEntry) {
// 1.
guard let index = (sections[.daily] as? [DailyEntry])?.firstIndex(of: dailyEntry) else {
return
}
// 2.
var mutableCopy = dailyEntry
// 3.
mutableCopy.selected = true
extension WeatherViewModel {
mutating func select(dailyEntry: DailyEntry) {
// 1.
guard let index = (sections[.daily] as? [DailyEntry])?.firstIndex(of: dailyEntry) else {
return
}
// 2.
var mutableCopy = dailyEntry
// 3.
mutableCopy.selected = true
extension WeatherViewController {
func configure(with viewModel: WeatherViewModel) {
self.viewModel = viewModel
title = viewModel.title
reloadData()
}
private func makeSnapshot() -> NSDiffableDataSourceSnapshot<WeatherViewModel.Section, WeatherViewModel.Item> {
var snapshot = NSDiffableDataSourceSnapshot<WeatherViewModel.Section, WeatherViewModel.Item>()