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
class CachedDateFormatter { | |
static let sharedInstance = CachedDateFormatter() | |
var cachedDateFormatters = [String: NSDateFormatter]() | |
func formatterWith(#format: String, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale(localeIdentifier: "en_US")) -> NSDateFormatter { | |
let key = "\(format.hashValue)\(timeZone.hashValue)\(locale.hashValue)" | |
if let cachedDateFormatter = cachedDateFormatters[key] { | |
return cachedDateFormatter | |
} |
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
// http://blog.krzyzanowskim.com | |
import Cocoa | |
struct ChunkSequence<Element>: SequenceType { | |
let chunkSize: Array<Element>.Index | |
let collection: Array<Element> | |
func generate() -> AnyGenerator<ArraySlice<Element>> { | |
var offset:Array<Element>.Index = collection.startIndex |
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
protocol StackType { | |
typealias Element | |
mutating func push(element: Element) | |
mutating func pop() -> Element? | |
} | |
final class BufferStorage<Element> { | |
private var ptr: UnsafeMutablePointer<Element> | |
private let capacity: Int |
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 | |
extension NSObject { | |
var isPublicClass: Bool { | |
return self.dynamicType.isPublicClass | |
} | |
class var isPublicClass: Bool { | |
return _PUBLIC_IOS_CLASSES.contains(NSStringFromClass(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
// | |
// UILabel+JumpingDots.swift | |
// JumpingDots | |
// | |
// Copyright (c) 2016 Arkadiusz Holko. All rights reserved. | |
// | |
import UIKit | |
import ObjectiveC |
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
NSString * L(NSString * translation_key, NSString * lang) { | |
NSString * s = NSLocalizedString(translation_key, nil); | |
// Force translation as "Lang" language if no translations are found | |
if ([s isEqualToString:translation_key]) { | |
NSString * path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"]; | |
NSBundle * languageBundle = [NSBundle bundleWithPath:path]; | |
s = [languageBundle localizedStringForKey:translation_key value:@"" table:nil]; | |
} |
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
#!/usr/bin/env xcrun swift | |
// $ chmod +x script.swift | |
// $ ./script.swift | |
// or $ ./script.swift -xcode=/Applications/Xcode-beta.app | |
import Foundation | |
@noreturn private func failWithError(message: String) { | |
print("π« \(message)") |
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
class Thunder { } | |
class Fire { } | |
protocol Pokemon { | |
typealias PokemonType | |
func attack(move:PokemonType) | |
} | |
struct Pikachu: Pokemon { | |
typealias PokemonType = Thunder |
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 | |
struct Person { | |
let name: String | |
let city: String | |
} | |
let people = [ | |
Person(name: "Chris", city: "Berlin"), | |
Person(name: "Natasha", city: "Tokyo"), |
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
protocol QueueType { | |
typealias Element | |
mutating func enqueue(element: Element) | |
mutating func dequeue() -> Element? | |
func peek() -> Element? | |
} | |
final class Storage<Element> { |