Skip to content

Instantly share code, notes, and snippets.

Avatar

Marco Santarossa MarcoSantarossa

View GitHub Profile
View SwiftJestTests.swift
import XCTest
@testable import SampleApp
final class SampleAppTests: XCTestCase {
func testExample() {
expect("myValue").not().toBeNil()
expect(5).toBe(5)
View binder.swift
import UIKit
typealias EmptyClosure = () -> Void
final class MyEW {
let onDo: EmptyClosure
init(onDo: @escaping EmptyClosure) {
self.onDo = onDo
}
View Localization.swift
protocol Localizable {
associatedtype LocalizableKey
static var tableName: String? { get }
static func localize(key: LocalizableKey, localizer: LocalizerType) -> String
}
extension Localizable where LocalizableKey: RawRepresentable {
static var tableName: String? {
View CacheLRU.swift
final class CacheLRU<Key: Hashable, Value> {
private struct CachePayload {
let key: Key
let value: Value
}
private let capacity: Int
private let list = DoublyLinkedList<CachePayload>()
private var nodesDict = [Key: DoublyLinkedListNode<CachePayload>]()
@MarcoSantarossa
MarcoSantarossa / AsyncOperation.swift
Last active Feb 2, 2021
How to write and use an asynchronous operation
View AsyncOperation.swift
import Foundation
class AsyncOperation: Operation {
enum State: String {
case isReady, isExecuting, isFinished
}
override var isAsynchronous: Bool {
return true
}