Skip to content

Instantly share code, notes, and snippets.

View ksm's full-sized avatar
🏔️

Karol S. Mazur ksm

🏔️
View GitHub Profile
/// |                    World                 |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|
  1. World is a module
  2. World is aware of all modules.
  3. Modules aren't aware of World.
// Created by Marcin Krzyzanowski
import Foundation
public protocol JSONEncodable: Encodable { }
public extension JSONEncodable {
func toJSON(using encoder: @autoclosure () -> JSONEncoder = JSONEncoder()) throws -> String {
try String(decoding: encoder().encode(self), as: UTF8.self)
}
@khanlou
khanlou / SKSerialInputStream.h
Last active November 10, 2022 11:41
Partially adapted from AFMultipartBodyStream
//
// SKSerialInputStream.h
// inputstream
//
// Created by Soroush Khanlou on 11/4/18.
// Copyright © 2018 Soroush Khanlou. All rights reserved.
//
#import <Foundation/Foundation.h>
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
@BeauNouvelle
BeauNouvelle / UIBarButtonItem Closure 1.swift
Last active April 11, 2019 02:46
UIBarButtonItem Closure
extension UIBarButtonItem {
/// Typealias for UIBarButtonItem closure.
private typealias UIBarButtonItemTargetClosure = (UIBarButtonItem) -> ()
private class UIBarButtonItemClosureWrapper: NSObject {
let closure: UIBarButtonItemTargetClosure
init(_ closure: @escaping UIBarButtonItemTargetClosure) {
self.closure = closure
}
@AliSoftware
AliSoftware / Coordinators-v2.swift
Last active May 4, 2023 12:26
Our implementation of the Coordinators pattern — V2, more strict than V1
// Coordinator.swift
import Foundation
public protocol Coordinator: class {
var components: CoordinatorComponents { get }
/// Set up here everything that needs to happen just before the Coordinator is presented
///
/// - Parameter modalSetup: A parameter you can use to customize the default mainViewController's
@karwa
karwa / codablebridge.swift
Created November 1, 2017 04:57
codable-nscoding bridge
import Foundation
/// This isn't safe to use before Swift gets ABI stability, because generic classes
/// could change their names. Also, be sure to register bridges with the Obj-C runtime
/// if using to decode during iOS state restoration.
///
class CodableBridge<Wrapped: Codable>: NSObject, NSSecureCoding {
let value: Wrapped
init(_ value: Wrapped) { self.value = value }
@chriseidhof
chriseidhof / references.swift
Last active October 14, 2021 10:24
References Blogpost
//: Playground - noun: a place where people can play
import Foundation
final class Disposable {
private let dispose: () -> ()
init(_ dispose: @escaping () -> ()) {
self.dispose = dispose
}
@chriseidhof
chriseidhof / sample.swift
Last active December 6, 2019 22:52
Observable References
import Foundation
// A lens is a getter and a setter combined
struct Lens<Whole, Part> {
let get: (Whole) -> Part
let set: (inout Whole, Part) -> ()
}
// We can create a lens from a key path
extension Lens {
@kharrison
kharrison / Country.swift
Last active February 16, 2021 15:35
Swift Hash Functions
import Foundation
struct Country {
let name: String
let capital: String
var visited: Bool
}
extension Country: Equatable {
static func == (lhs: Country, rhs: Country) -> Bool {