Skip to content

Commit c8c2c21

Browse files
authored
Add optional value to ExplicitNull and ServerTimestamp (#3784)
* Add optional value to ExplicitNull and ServerTimestamp * Fixing comments * another comment fix
1 parent 1ce982d commit c8c2c21

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Firestore/Swift/Source/Codable/ExplicitNull.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public enum ExplicitNull<Wrapped> {
3838
}
3939
}
4040

41-
/// Get the `Optional` representation of `ExplicitNull`.
42-
public var value: Wrapped? {
41+
/// Returns this value as an `Optional<Wrapped>`.
42+
public var optionalValue: Wrapped? {
4343
switch self {
4444
case .none:
4545
return .none

Firestore/Swift/Source/Codable/FieldValue+Encodable.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public enum ServerTimestamp: Codable, Equatable {
4949
/// value to `stamp`.
5050
case resolved(Timestamp)
5151

52+
/// Returns this value as an `Optional<Timestamp>`.
53+
///
54+
/// If the server timestamp is still pending, the returned optional will be `.none`.
55+
/// Once resolved, the returned optional will be `.some` with the resolved timestamp.
56+
public var timestamp: Timestamp? {
57+
switch self {
58+
case .pending:
59+
return .none
60+
case let .resolved(timestamp):
61+
return .some(timestamp)
62+
}
63+
}
64+
5265
public init(from decoder: Decoder) throws {
5366
let container = try decoder.singleValueContainer()
5467
if container.decodeNil() {

0 commit comments

Comments
 (0)