This file contains 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
public struct CountedSet<Element : Hashable> : Hashable, CollectionType, ArrayLiteralConvertible { | |
public typealias Index = SetIndex<Element> | |
public typealias Generator = SetGenerator<Element> | |
private var backingSet = Set<Element>() | |
private var countMapping = [Int: UInt]() | |
private var debugCountMapping: [Element : UInt] { | |
var result = [Element : UInt]() | |
backingSet.forEach { element in |
This file contains 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 | |
// Defining this breaks the behaviour of the existing '||' operator in some cases | |
public func ||(lhs: NSPredicate, rhs: NSPredicate) -> NSPredicate { | |
return NSCompoundPredicate(orPredicateWithSubpredicates: [lhs, rhs]) | |
} | |
func foo() { | |
let cards = [String: [String]]() | |
let startingContactIndex: UInt = 3 |
This file contains 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
struct Car { | |
let made: String | |
} | |
func compareDumps(lhs: Any, rhs: Any) -> Bool { | |
var (lhsDump, rhsDump) = (String(), String()) | |
dump(lhs, to: &lhsDump) | |
dump(rhs, to: &rhsDump) | |
return lhsDump == rhsDump | |
} |
This file contains 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
NSMutableDictionary *vibrationParameters = [[NSMutableDictionary alloc] init]; | |
vibrationParameters[@"VibePattern"] = @[@YES, @100]; | |
vibrationParameters[@"Intensity"] = @1; | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Wimplicit-function-declaration" | |
AudioServicesStopSystemSound(kSystemSoundID_Vibrate); | |
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, vibrationParameters); | |
#pragma clang diagnostic pop |
This file contains 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
public extension IteratorProtocol { | |
mutating public func any(_ predicate: (Element) throws -> Bool) rethrows -> Bool { | |
guard let current = next() else { return false } | |
return try predicate(current) || any(predicate) | |
} | |
mutating public func all(_ predicate: (Element) throws -> Bool) rethrows -> Bool { | |
guard let current = next() else { return true } | |
return try predicate(current) && all(predicate) |
This file contains 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 UIKit | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
extension Comparable { | |
/// Clamp the value between `low` and `high` | |
func clamp(_ low: Self, _ high: Self) -> Self { |
This file contains 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
extension DispatchQueue { | |
/// Helper method to use when reading from a resource | |
/// that is being isolated by this queue. | |
/// | |
/// Using this method retriving a value like this: | |
/// ``` | |
/// var result: T? | |
/// queue.sync { | |
/// result = resource["key"] |
This file contains 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
extension String { | |
subscript(index: Int) -> Character { | |
return self[startIndex.advancedBy(index)] | |
} | |
subscript(range: Range<Int>) -> String { | |
let start = startIndex.advancedBy(range.startIndex) | |
let end = startIndex.advancedBy(range.endIndex) |
This file contains 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 | |
import SystemConfiguration | |
extension Notification.Name { | |
public static let reachabilityChanged = Notification.Name(rawValue: "reachabilityChanged") | |
} | |
protocol ReachabilityObserver: class { | |
func reachabilityDidChange(_ reachability: Reachability) | |
} |
This file contains 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 | |
final class Log: NSObject { | |
enum Topic: String { | |
case network, app | |
} | |
private enum Level: String { | |
case info = "" |