Skip to content

Instantly share code, notes, and snippets.

View cristhianleonli's full-sized avatar

Cristhian Leon cristhianleonli

View GitHub Profile
import Foundation
import SwiftUI
struct CachedAsyncImage<Content, Placeholder>: View where Content: View, Placeholder: View {
@ViewBuilder private let content: (Image) -> Content
@ViewBuilder private let placeholder: () -> Placeholder
@ObservedObject var imageLoader: ImageLoader
init(

Keybase proof

I hereby claim:

  • I am cristhianleonli on github.
  • I am cristhianleonli (https://keybase.io/cristhianleonli) on keybase.
  • I have a public key ASD5sSFRaF5hGY-bwVAv0XDwXGGjkP77siYzOmsngeUwAgo

To claim this, I am signing this object:

//
// ReactiveViewModel.swift
// MVRxVM
//
// Created by Cristhian Leon on 2022.
//
import Foundation
import Combine
import Foundation
import SwiftUI
// 1. The actual Decodable structure
struct CatFact: Codable {
// 2. nested codable structure
struct Status: Codable {
let verified: Bool
let sentCount: Int
import Foundation
extension Decodable {
static func parse(from item: Any?, strategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) -> Self? {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = strategy
do {
guard let data = self.data(from: item) else {
return nil
import Foundation
extension Array {
func sorted<T: Comparable>(by compare: (Element) -> T, asc ascendant: Bool = true) -> Array {
return self.sorted {
if ascendant {
return compare($0) < compare($1)
}
return compare($0) > compare($1)
extension UIStoryboard {
func instantiateViewController<T>(ofType type: T.Type = T.self) -> T where T: UIViewController {
let controller = instantiateViewController(withIdentifier: type.reuseId)
guard let viewController = controller as? T else {
fatalError()
}
return viewController
import UIKit
typealias ActionHandler = () -> Void
class Alert: UIView {
// MARK: - Outlets
@IBOutlet private var container: UIView!
@IBOutlet private var titleLabel: UILabel!
import Foundation
protocol Reusable {
static var reuseIdentifier: String { get }
}
extension Reusable {
static var reuseIdentifier: String {
return String(describing: self)
}
import Foundation
public extension String {
/// just a wrapper for int type
typealias IndexInt = Int
/// just a wrapper for int type
typealias DistanceInt = Int