Skip to content

Instantly share code, notes, and snippets.

View DeFrenZ's full-sized avatar

Davide De Franceschi DeFrenZ

View GitHub Profile
@DeFrenZ
DeFrenZ / FSLVExample.swift
Created November 17, 2014 11:54
FiniteStateLayoutView
//
// FSLVExample.swift
// FSLVExample
//
// Created by Davide De Franceschi on 16/11/14.
// Copyright (c) 2014 Davide De Franceschi. All rights reserved.
//
import UIKit
@DeFrenZ
DeFrenZ / JSON.swift
Last active March 7, 2016 09:44
Swift JSON
//
// JSON.swift
// Boppl
//
// Created by Davide De Franceschi on 26/06/2015.
// Copyright (c) 2015 Boppl. All rights reserved.
//
import Foundation
@DeFrenZ
DeFrenZ / EnumerablePlayground
Created February 18, 2015 00:34
Trying for coalescence in Swift
// Playground - noun: a place where people can play
import Swift
struct Yield2Generator<S: SequenceType, C: CollectionType>: GeneratorType {
var sequenceGenerator: S.Generator
var sequenceElement: S.Generator.Element?
let collection: C
var collectionGenerator: C.Generator
init(_ sequenceGenerator : S.Generator, _ collection : C) {
@DeFrenZ
DeFrenZ / Dependencies.swift
Created March 5, 2015 08:34
FuturePlayground
// Copyright (c) 2014 Rob Rix. All rights reserved.
// MARK: BoxType
/// The type conformed to by all boxes.
public protocol BoxType {
/// The type of the wrapped value.
typealias Value
/// Initializes an intance of the type with a value.
@DeFrenZ
DeFrenZ / DZPositionedImageButton.swift
Created July 9, 2015 17:06
UIButton subclass for having the image at different positions
//
// DZPositionedImageButton.swift
// Boppl
//
// Created by Davide De Franceschi on 18/05/2015.
// Copyright (c) 2015 Boppl. All rights reserved.
//
import UIKit
protocol Foo: Hashable {
var id: Int { get }
}
extension Foo {
var hashValue: Int { return id }
}
extension Int: Foo {
var id: Int { return self }
}
//MARK: - ??=
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??= <Wrapped> (inout optional: Wrapped?, @autoclosure defaultValue: () throws -> Wrapped?) rethrows {
optional = try optional ?? defaultValue()
}
//
// DZKeyboardLayoutProxyView.swift
//
// Created by Davide De Franceschi on 25/02/2015.
//
import UIKit
final class DZKeyboardLayoutProxyView: UIView {
private var keyboardObserver: NSObjectProtocol?
@DeFrenZ
DeFrenZ / Route.swift
Created February 24, 2020 16:15
Type-safe Route
import Foundation
struct Route<T: PartialConvertible> {
let components: [Component]
enum Component {
case literal(String)
case component(
parse: (String, inout Partial<T>) -> Bool,
resolve: (T) -> String
@DeFrenZ
DeFrenZ / AppDelegate.swift
Created November 14, 2020 23:59
Dependency Injection a-la SwiftUI.Environment style by (ab)using the responder chain
import UIKit
@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
private let testService: TestService = .init()
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration