Skip to content

Instantly share code, notes, and snippets.

@jeremiegirault
jeremiegirault / Swift4Compat.swift
Created June 14, 2017 15:07
Swift helper for compatibility
//
// Swift4Compat.swift
// openrider
//
// Created by Jeremie Girault on 14/06/2017.
// Copyright © 2017 EC1. All rights reserved.
//
import UIKit
@jeremiegirault
jeremiegirault / UILayoutPriority+operations.swift
Created June 11, 2017 19:03
Helpers for UILayoutPriority for swift 4
extension UILayoutPriority: ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral {
public init(floatLiteral value: Float) {
self.init(rawValue: value)
}
public init(integerLiteral value: Int) {
self.init(rawValue: Float(value))
}
public static func +(lhs: UILayoutPriority, rhs: UILayoutPriority) -> UILayoutPriority {
// The sad state of tuples in swift 4
func test() {
return () // why is it not mandatory ?
}
// func test() -> Void {} // error: invalid redeclaration of 'test()' why is it a redefinition ?
/*
The problem is that Void in swift is not the "Absence" of a parameter but the type of the empty tuple
We should change the definition to:
@jeremiegirault
jeremiegirault / CustomTransform.swift
Created May 31, 2017 14:17
Rx Custom transformations
protocol CustomTransform {
associatedtype Result
func apply(_ sink: (Result) -> Void)
}
enum FilterMap<Result>: CustomTransform {
case filter
case map(Result)
//: [Previous](@previous)
import UIKit
import PlaygroundSupport
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 400))
var test: Bool = false
class Handler: NSObject {
@jeremiegirault
jeremiegirault / fonts-openrider.stencil
Last active May 24, 2017 13:44
My custom swiftgen templates for strings and fonts
// Generated using SwiftGen, template by @jeremiegirault — https://github.com/SwiftGen/SwiftGen
#if os(iOS) || os(tvOS) || os(watchOS)
import UIKit.UIFont
typealias Font = UIFont
#elseif os(OSX)
import AppKit.NSFont
typealias Font = NSFont
#endif
@jeremiegirault
jeremiegirault / AssertComplete.swift
Last active May 23, 2017 10:22
Ensure that the consumer of your api calls your callback
final class AssertComplete {
var defused: Bool = false
let function: String
init(function: String = #function) {
self.function = function
}
func defuse() { defused = true }
import UIKit
import RxSwift
private var disposeBagKey: UInt8 = 0
private final class KeyboardObserver {
private static var key: UInt8 = 0
let guide = UILayoutGuide()
@jeremiegirault
jeremiegirault / KeyboardObserver.swift
Last active March 13, 2017 13:23
Handle iOS keyboard with autolayout
private final class KeyboardObserver {
private static var key: UInt8 = 0
let guide = UILayoutGuide()
private var isAttached = false
private let top: NSLayoutConstraint
private let left: NSLayoutConstraint
private let width: NSLayoutConstraint
private let height: NSLayoutConstraint
@jeremiegirault
jeremiegirault / Observable+consolidate.swift
Last active December 7, 2016 09:11
Rx state consolidation
import Foundation
import RxSwift
fileprivate final class MutableReference<T> {
var value: T
init(_ value: T) { self.value = value }
}
struct SideEffect<State> {