Last active
May 4, 2018 09:26
-
-
Save shaps80/1cf3153b80ae7a6da02b06ac311fe7b6 to your computer and use it in GitHub Desktop.
Adds `isNilOrEmpty` to any `Collection` – Swift 4
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 extension Optional where Wrapped: Collection { | |
| /// Equivalent to `if let value = value, !value.isEmpty` | |
| /// | |
| /// Useful when you need to know whether or not an underlying value exists at all. | |
| /// | |
| /// string.isNilOrEmpty | |
| /// | |
| /// Returns true if `string` is nil or empty. False otherwise | |
| var isNilOrEmpty: Bool { | |
| switch self { | |
| case .some(let wrapped): return wrapped.isEmpty | |
| case .none: return true | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment