Skip to content

Instantly share code, notes, and snippets.

View isaac-weisberg's full-sized avatar
💭
🤔🤔🤔

Isaac Weisberg isaac-weisberg

💭
🤔🤔🤔
View GitHub Profile
import UIKit
protocol IImageProvider: AnyObject {
func retrieve(_ completion: @escaping (UIImage?) -> Void)
func preload()
}
protocol IImageProviderConsumer {
var currentProvider: IImageProvider? { get set }
import UIKit
class AutoscaleImageView: UIImageView {
var aspectRatioConstraint: NSLayoutConstraint?
override init(image: UIImage?) {
super.init(image: image)
recalculateAspectRatioConstraint()
}
struct ApartmentPlacement: Equatable {
let entrance: Int
let floor: Int
let location: Int
}
func calculateApartmentPlacement(for apartmentNumber: Int, totalEntrances: Int, totalFloors: Int) -> ApartmentPlacement? {
let apartmentIndex = apartmentNumber - 1
guard totalEntrances > 0, totalFloors > 0 else {
return nil
class TransactionCellView: UIView {
// ... other members omitted ...
let acceptButton = TransactionCellAcceptButton()
var iconToBottomConstraint: NSLayoutConstraint!
var acceptButtonToBottomConstraint: NSLayoutConstraint!
init(viewModel: TransactionCellViewModel) {
// ... omitted configuration of the view style ...
// ... omitted AutoLayout code ...
protocol TransactionCellViewModel {
var icon: String { get }
var name: String { get }
var amount: NSDecimalNumber { get }
// Added in the following updates
var shouldShowAcceptButton: Bool { get }
}
class TransactionCellView: UIView {
let iconImageView = UIImageView()
let nameLabel = UILabel()
let amountLabel = UILabel()
init(viewModel: TransactionCellViewModel) {
// ... omitted configuration of the view style ...
// ... omitted AutoLayout code ...
class TransactionTable: CustomTableView {
override init(viewModel: TransactionTableViewModel) {
super.init()
viewModel.transactionViewModels.forEach { transactionViewModel in
switch transactionViewModel {
case .info(let viewModel):
let cell = TransactionInfoCell(viewModel: viewModel)
self.addCell(cell)
class TransactionTableViewModel {
// ... omitted ...
init(di: DI) {
self.transactionViewModels = di.transactionListService.getTransactionModels()
.map { transactionModel -> TransactionCellViewModel in
if transactionModel.isPendingAccept {
let viewModel = TransactionInfoWAcceptViewModel(model: transactionModel)
viewModel.acceptButtonTap
.map { _ in
enum TransactionCellViewModel {
case info(TransactionInfoCellViewModel)
case infoPendingAccept(TransactionInfoWAcceptViewModel)
}
class TransactionTableViewModel {
typealias DI = HasTransactionListService
let transactionViewModels: [TransactionCellViewModel]
class NavigationEvents {
let showTransactionAcceptScreen = PublishRelay<String>()
}
let navigation = NavigationEvents()