Skip to content

Instantly share code, notes, and snippets.

// Copyright (c) 2021 Manuel Maly
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
{
"Version": 1,
"Metadata": {
"Project": "",
"Created": ""
},
"Pattern": [
{
"Event":
{
import UIKit
import Combine
class ChatViewController: UIViewController {
var cancellables = Set<AnyCancellable>()
let viewModel: ChatViewModel
init(viewModel: ChatViewModel) {
self.viewModel = viewModel
import UIKit
import Combine
protocol DiffableListDataSourceType {
associatedtype SectionIdentifier: Hashable
associatedtype ItemIdentifier: Hashable
func apply(_ snapshot: NSDiffableDataSourceSnapshot<SectionIdentifier, ItemIdentifier>,
animatingDifferences: Bool,
completion: (() -> Void)?)
class AdjustableVisualEffectView: UIVisualEffectView {
private var animator: UIViewPropertyAnimator!
init(effect: UIVisualEffect?, intensity: CGFloat) {
super.init(effect: nil)
self.animator = UIViewPropertyAnimator(duration: 1, curve: .linear) { [weak self] in
self?.effect = effect
}
self.intensity = intensity
import UIKit
class PixelWidthConstraint: NSLayoutConstraint {
override func awakeFromNib() {
super.awakeFromNib()
constant = 1.0 / UIScreen.main.scale
}
}
import RxSwift
import Moya
import Unbox
public extension ObservableType where E == Response {
public func mapObject<T: Unboxable>(type: T.Type) -> Observable<T> {
return flatMap { response -> Observable<T> in
return Observable.just(try response.mapObject(type: T.self))
}
}
protocol ViewModelType {
associatedtype Model
associatedtype Input
init(model: Model, input: Input)
}
class ViewModel: ViewModelType {
protocol ViewModelType {
associatedtype Model
associatedtype Input
init(model: Model, input: Input)
}
class ViewModel: ViewModelType {
required init(model: Model, input: Input) {
// Neat way of avoiding if lets/guard lets
extension Optional {
func then(_ handler:(Wrapped) -> Void) {
switch self {
case .some(let value): handler(value)
case .none: break
}
}