Skip to content

Instantly share code, notes, and snippets.

View lorentey's full-sized avatar
⚙️

Karoy Lorentey lorentey

⚙️
View GitHub Profile
@lorentey
lorentey / inference-snafu.swift
Last active June 2, 2016 22:05
The following snippet compiles under Swift 2.2, but not Swift 3. It defines a (quite useless) left shift operator on `Double` values. For some reason, Swift 3's type inference engine can go awry when such a shift operator is used in a subexpression.
public func <<(num: Double, exp: Int) -> Double {
return num * Double(1 << exp)
}
let s = (0.5 << 5) - 1
print(s)
@lorentey
lorentey / Mutable Class Method.swift
Created December 12, 2015 00:01
You wouldn't expect calling a method on a class to modify the variable holding a reference to the instance, but it can happen.
//: Playground - noun: a place where people can play
import UIKit
protocol MagicProtocol {
}
extension MagicProtocol {
mutating func magic(xyzzy: Self) {
// Mutating methods defined in a protocol extension can mutate `self` even if
// the protocol is implemented by a class.