Created
May 4, 2017 03:40
-
-
Save xuyazhong/5cf2fadf80096a1ab30ec8c2e4eb90b8 to your computer and use it in GitHub Desktop.
Optional
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
https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift | |
public enum Optional<Wrapped> : ExpressibleByNilLiteral { | |
// The compiler has special knowledge of Optional<Wrapped>, including the fact | |
// that it is an `enum` with cases named `none` and `some`. | |
/// The absence of a value. | |
/// | |
/// In code, the absence of a value is typically written using the `nil` | |
/// literal rather than the explicit `.none` enumeration case. | |
case none | |
/// The presence of a value, stored as `Wrapped`. | |
case some(Wrapped) | |
/// Creates an instance that stores the given value. | |
@_transparent | |
public init(_ some: Wrapped) { self = .some(some) } | |
/// Creates an instance initialized with `nil`. | |
/// | |
/// Do not call this initializer directly. It is used by the compiler when you | |
/// initialize an `Optional` instance with a `nil` literal. For example: | |
/// | |
/// var i: Index? = nil | |
/// | |
/// In this example, the assignment to the `i` variable calls this | |
/// initializer behind the scenes. | |
@_transparent | |
public init(nilLiteral: ()) { | |
self = .none | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment