Skip to content

Instantly share code, notes, and snippets.

@crazytonyli
Created October 13, 2015 02:16
Show Gist options
  • Select an option

  • Save crazytonyli/c3554df7e5f039b9ef78 to your computer and use it in GitHub Desktop.

Select an option

Save crazytonyli/c3554df7e5f039b9ef78 to your computer and use it in GitHub Desktop.
extension Optional where Wrapped: IntegerType {
func nilOrZero() -> Bool {
switch self {
case .None: return true
case .Some(let value): return value == 0
}
}
}
var arr: [Int]?
arr?.count == 0 // false
(arr?.count).nilOrZero() // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment