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 SwiftUI | |
| import WidgetKit | |
| struct Mode1: Codable { | |
| var foo: String | |
| } | |
| struct Mode2: Codable { | |
| var bar: String | |
| } |
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
| // Current HTTPStream: | |
| protocol HTTPStream: Stream { | |
| static func makeStream() -> Self | |
| func bind(to ip: String?, on port: Int) throws | |
| func accept(max connectionCount: Int, handler: (HTTPStream -> Void)) throws | |
| func listen() throws | |
| func receiveByte() throws -> Byte? |
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
| let items = [1, 2, 3] as Any | |
| if let items = items as? [Any] { // This cast fails | |
| print("it works") // and this is never printed | |
| } |
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 Job { | |
| case Mechanic(String) | |
| case Carpenter(String) | |
| } | |
| extension Job: CerealType { | |
| private struct Keys { | |
| static let job = "job" | |
| static let name = "name" | |
| } |
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" |
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
| 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
| /** | |
| 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
| 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
| 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 | |
| } |
NewerOlder