Author: Chris Lattner
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
| extension Result { | |
| public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> { | |
| flatMapError { _ in | |
| .init { try handler() } | |
| } | |
| } | |
| public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> { | |
| flatMapError { error in | |
| .init { try handler(error) } |
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 UIKit | |
| protocol DefaultValue { | |
| associatedtype Value: Decodable | |
| static var defaultValue: Value { get } | |
| } | |
| @propertyWrapper | |
| struct Default<T: DefaultValue> { | |
| var wrappedValue: T.Value |
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
| extension AnyObserver { | |
| static func create<E>(_ relay: PublishRelay<E>) -> AnyObserver<E> { | |
| return .init { event in | |
| guard case let .next(value) = event else { return } | |
| relay.accept(value) | |
| } | |
| } | |
| static func create<E>(_ relay: BehaviorRelay<E>) -> AnyObserver<E> { | |
| return .init { event in |
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
| // Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24 | |
| import Foundation | |
| private struct JSONCodingKeys: CodingKey { | |
| var stringValue: String | |
| init(stringValue: String) { | |
| self.stringValue = stringValue | |
| } | |
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 UIKit | |
| class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
| @IBOutlet weak var tableView: UITableView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| NSLayoutConstraint.activate([ | |
| tableView.topAnchor.constraint(equalTo: view.topAnchor), |
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 | |
| // Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a | |
| struct JSONCodingKeys: CodingKey { | |
| var stringValue: String | |
| init?(stringValue: String) { | |
| self.stringValue = stringValue | |
| } |
- Proposal: SE-XXXX
- Authors: Chris Lattner, Joe Groff
Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.
This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.
- Mac OS X 背后的故事(一)力挽狂澜的Ellen Hancock
- Mac OS X 背后的故事(二)Linus Torvalds的短视
- Mac OS X 背后的故事(三)Mach之父Avie Tevanian
- Mac OS X 背后的故事(四)政客的跨界
- Mac OS X 背後的故事(五)Jean-Marie Hullot 的天才天才發明 Interface Builder
- Mac OS X 背后的故事(六)上善若水 Cordell Ratzlaff 引发的 Aqua 革命(上)
- Mac OS X 背後的故事(七)上善若水 Cordell Ratzlaff 引發的 Aqua 革命(下)
- Mac OS X 背後的故事(八)三好學生 Chris Lattner 的 LLVM 編譯工具鏈
- Mac OS X 背後的故事(九)半導體的豐收(上)
- [Mac OS X 背後的故事(十)半導體的豐收(中)](https
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 recursive(observable: Observable<Int>) -> Observable<Int> { | |
| return observable.flatMap { value -> Observable<Int> in | |
| guard value < 10 else { | |
| return Variable(-1).asObservable() | |
| } | |
| print(value) | |
| return recursive(Variable(value + 1).asObservable()) | |
| } | |
| } |
NewerOlder