Skip to content

Instantly share code, notes, and snippets.

import Cocoa
// Only needed until we have class variables
var __SwizzleSayHello = { (who:String) -> String in
return "Hello, \(who)"
}
class Swizzle {
//Only needed until we have class variables
class var _sayHello : (String)->String { get{ return __SwizzleSayHello } set (swizzle) {__SwizzleSayHello = swizzle} }
@SwiftStudies
SwiftStudies / IncrementalUpdateTests.swift
Last active August 29, 2015 14:21
Incremental Update Challenge
//
// IncrementalUpdateTests.swift
//
// Copyright (c) 2015 Swift Studies. All rights reserved.
//
import Foundation
import XCTest
//: Playground - noun: a place where people can play
import Cocoa
func f1(x : Int) -> Int? {
return (x == 3) ? 1 : 3
}
func f2(x : Int) -> Int? {
if x < 0 || x > 3 {return nil}
@SwiftStudies
SwiftStudies / OnTheNatureOfSelf.swift
Last active May 11, 2018 20:08
Can anyone solve this problem with an extension for classes (non final) and return type from a prototype requirement on a static function?
import Foundation
public protocol BigData {
static func cache(from path:String)->Self
}
extension String : BigData {
public static func cache(from path: String) -> String {
return (try? String(contentsOfFile: path)) ?? "Could not load"
}