Skip to content

Commit

Permalink
Add Zero and One providers
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezreal committed Feb 8, 2020
1 parent 5b59648 commit 6afea22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ It provides an empty instance of a `String`, `Array` or any type that implements
### `True` and `False`
Provide `true` and `false` respectively for `Bool` properties.

### `Zero` and `One`
Provide `0` and `1` respectively for `Int` properties.

### `FirstCase`
It provides the first case of an `enum` type as the default value. The `enum` must implement the `CaseIterable` protocol.

Expand Down
8 changes: 8 additions & 0 deletions Sources/DefaultCodable/DefaultValueProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ public enum Empty<A>: DefaultValueProvider where A: Codable, A: Equatable, A: Ra
public enum FirstCase<A>: DefaultValueProvider where A: Codable, A: Equatable, A: CaseIterable {
public static var `default`: A { A.allCases.first! }
}

public enum Zero: DefaultValueProvider {
public static let `default` = 0
}

public enum One: DefaultValueProvider {
public static let `default` = 1
}
2 changes: 1 addition & 1 deletion Tests/DefaultCodableTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
[
testCase(DefaultTests.allTests),
]
}
Expand Down

0 comments on commit 6afea22

Please sign in to comment.