func ?? <T>(_ optional: T?, _ trap: @autoclosure () -> Never) -> T {
switch optional {
case .some(let value):
return value
case .none:
trap()
}
}
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 Darwin | |
| import UIKit | |
| protocol _LoggerDelegate : AnyObject { | |
| /// | |
| func logger(_ logger: Logger, received newString: String) | |
| } | |
| final class Logger { | |
| /// |
import UIKit
protocol ViewComponent : AnyObject {
///
func isAncestor(of descendant: Self) -> Bool
///
func isDescendant(of ancestor: Self) -> Bool
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 RxSwift | |
| public final class DisposeCache<Key> | |
| : ExpressibleByDictionaryLiteral where Key : Hashable { | |
| /// | |
| private var lock = NSRecursiveLock() | |
| /// | |
| private var storage: [Key: Disposable] |
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 ValueContainer { | |
| associatedtype Value | |
| var value: Value { get } | |
| init(_ value: Value) | |
| } | |
| extension ValueContainer where Self : Equatable, Value : Equatable { | |
| static func == (lhs: Self, rhs: Self) -> Bool { | |
| return lhs.value == rhs.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
| class Ref { | |
| weak var obj: Obj? { | |
| didSet { print("didSet", obj as Any) } | |
| } | |
| } | |
| class Obj { | |
| weak var ref: Ref? | |
| func unlink(from ref: Ref) { |
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
| public struct Unique<Key, Value>: Hashable where Key: Hashable { | |
| public enum KeyVariant { | |
| case key(Key) | |
| case keyPath(KeyPath<Value, Key>) | |
| case closure((Value) -> Key) | |
| internal func _key(for value: Value) -> Key { | |
| switch self { | |
| case .key(let key): |
The original proposal: https://github.com/DougGregor/swift-evolution/blob/property-delegates/proposals/NNNN-property-delegates.md
- A user can create custom property delegates that allow a
vardeclaration to decide how to implement the storage. - The original proposal want to use a new identifier space, prefixed by
$, to uniquely identify a property delegate from the computed and non-prefixed main property.
Size changes propagation to child view controller
In A Look Inside Presentation Controllers - WWDC 2014 session the following pattern was introduced.
- A
child view controlleror apresented view controllercan issue a request for size update by setting itspreferredContentSizeproperty. - A
parent view controlleror apresentation controllerwill receive a callback onpreferredContentSizeDidChangeForChildContentContainermethod. - At this point the receiver can decide if can allow the size request and layout the child view controller or the presented view controller.