This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Types for currency conversion | |
// https://www.natashatherobot.com/swift-money-phantom-types/ | |
import Foundation | |
struct Money { | |
enum Currency { | |
case GBP, EUR, USD | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Fruit { | |
case apple, pear, orange, plum | |
} | |
extension Fruit { | |
var cents: Int { | |
return switch self [ | |
.apple: 70, | |
.pear: 85, | |
.orange: 40, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol StageProtocol { | |
func perform() throws -> Self? | |
var queue: dispatch_queue_t { get } | |
func run(completion: (() throws -> Self) -> ()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Spinner from 'react-spinner'; | |
export default function loadable(hasLoadedTest, Component) { | |
return (props) => { | |
if (hasLoadedTest(props)) { | |
return <Component { ...props } />; | |
} | |
else { | |
return <Spinner />; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Foundation | |
protocol OptionalParasite { | |
typealias WrappedParasite | |
func toArray() -> [WrappedParasite] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Property Observing | |
// Swift 1.2 | |
import Cocoa | |
import XCPlayground | |
protocol ObjectListenerType { | |
func objectDidChange<T: AnyObject>(x: T) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ValueStorable { | |
subscript(key: String) -> AnyObject? { get set } | |
} | |
internal protocol ValueStorableUpdater { | |
init?(fromStorable storable: ValueStorable) | |
func updateStorable(inout storable: ValueStorable) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal enum FileInfoIdentifier: String { | |
case DisplayNameAndIcon = "displayNameAndIcon" | |
case DateModified = "dateModified" | |
var sortDescriptor: NSSortDescriptor { | |
switch self { | |
case .DisplayNameAndIcon: | |
return NSSortDescriptor(key:NSURLLocalizedNameKey, ascending:true) | |
case .DateModified: | |
return NSSortDescriptor(key:NSURLContentModificationDateKey, ascending:false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by Patrick Smith on 22/04/2015. | |
// Copyright 2015 Patrick Smith. | |
// Released under the MIT License http://opensource.org/licenses/MIT | |
import Cocoa | |
import WebKit | |
extension WKUserContentController { | |
func addBundledUserScript(scriptNameInBundle: String, injectAtStart: Bool = false, injectAtEnd: Bool = false, forMainFrameOnly: Bool = true, sourceReplacements: [String:String]? = nil) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Swift | |
import Cocoa | |
// Properties you need as an enum - problem of key value coding is it allows you to type *anything*, typos compile fine. | |
enum SyncObjectPropertyName { | |
case Archived | |
case Title | |
} | |
// Protocol shared both for local and server |