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
| require 'benchmark' | |
| class HashedFlags | |
| def initialize(opts = {}) | |
| @silly_prepend = opts.fetch(:silly_prepend, false) | |
| @uppercase = opts.fetch(:uppercase, false) | |
| end | |
| end | |
| SILLY_PREPEND = 0b00000001 |
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
| /* | |
| In Swift, you can overload operators. A common operator in Ruby for working with arrays is <<, | |
| which is syntatic sugar for array.push(). Since Array's in Swift don't take bitwise operations, this is | |
| an example demonstrating adding that operator to an array that contains any type. | |
| As an extra tidbit, I've added >> to prepend an array with an object | |
| */ | |
| @infix func << <T>(inout array: Array<T>, item: T) { | |
| array.append(item) |
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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>IDECodeSnippetCompletionPrefix</key> | |
| <string>swift_dispatch_once</string> | |
| <key>IDECodeSnippetCompletionScopes</key> | |
| <array> | |
| <string>All</string> | |
| </array> |
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
| /* | |
| This is a Swift Singleton. Lack of inline class variables right now make this a slightly more difficult task. | |
| Please ignore the oddly named class for the example. viewWillAppear made for good testing ;) | |
| */ | |
| class DetailViewController: UIViewController { | |
| func sharedInstance() -> DetailViewController { | |
| struct Container { | |
| static var instance: DetailViewController? | |
| static var token: dispatch_once_t = 0 |
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 | |
| public class ObserverContext: NSObject { | |
| public let keyPath: String | |
| public let options: NSKeyValueObservingOptions | |
| public var context = 0 | |
| public init(keyPath: String, options: NSKeyValueObservingOptions = nil) { | |
| self.keyPath = keyPath | |
| self.options = options | |
| } |
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
| func anyGenerator<Element>(initial: Element, body: (inout Element) -> Element?) -> AnyGenerator<Element> { | |
| return { | |
| var i: Element? = initial | |
| return anyGenerator { | |
| var r: Element? | |
| if var x = i { | |
| r = body(&x) | |
| i = x | |
| } |
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
| /** | |
| Find the first element in a sequence passing a test. | |
| :param: source Source sequence to iterate | |
| :param: includeElement Closure to evaluate elements with | |
| :return: First element in the sequence for which includeElement returns true, or nil if none found | |
| */ | |
| public func first<S: SequenceType>(source: S, includeElement: (S.Generator.Element) -> Bool) -> S.Generator.Element? { | |
| var filteredSource = lazy(source).filter(includeElement).generate() | |
| return filteredSource.next() |
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 Watable { } | |
| func arrayTest<Type: Watable>(v: [Type]) { | |
| if let unwrapped = v as? [Watable] { | |
| print("Success!: \(unwrapped)") | |
| } else { | |
| print("Failed :(") | |
| } | |
| } |
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 Watable { } | |
| extension Array: Watable { } | |
| func test<Type: Watable>(v: Type) { | |
| // Is there a way to tell if Type is an array with any type? | |
| } |
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 CoreData | |
| class WBManagedElement: NSManagedObject { | |
| } | |
| class ElementParameter: NSObject, NSSecureCoding { | |
| private struct Keys { | |
| static let element = "element" |
OlderNewer