Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Last active August 29, 2015 14:11
Show Gist options
  • Save ttepasse/1c6dbc225aed56eec744 to your computer and use it in GitHub Desktop.
Save ttepasse/1c6dbc225aed56eec744 to your computer and use it in GitHub Desktop.
Optionals with boolean values
// The following would be great, if not for this error message
// “Extension of generic type Optional<T> from a different module cannot provide public declarations”
//
// ... which seems to be a bug in Swift:
// https://twitter.com/jckarter/status/513429427179356161
extension Optional : BooleanType {
public var boolValue : Bool {
get {
switch (self) {
case .Some:
return true
case .None:
return false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment