Skip to content

Instantly share code, notes, and snippets.

@dwaite
Created February 12, 2016 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwaite/60c8dc05e498b747d0f2 to your computer and use it in GitHub Desktop.
Save dwaite/60c8dc05e498b747d0f2 to your computer and use it in GitHub Desktop.
enum Booly {
case truth
case falsehood
static let yes:Booly = truth
static let no:Booly = falsehood
static func defaulted() -> Booly {
return truth
}
static func workingYesVersion() -> Booly {
return yes
}
}
extension Booly {
func isDefault() -> Bool {
return self == truth
}
func brokenYesVersion() -> Bool {
// return self == yes // Error: Static member 'yes' cannot be used on instance of type 'Booly'
return self == .yes
}
}
import Foundation
let flags:CFStringCompareFlags = [.CompareAnchored]
switch flags {
// case .CompareAnchored: // Error: Enum case 'CompareAnchored' ont found in type 'CFStringCompareFlags'
case CFStringCompareFlags.CompareAnchored:
print("Anchored")
default:
()
}
let b:Booly = .yes
// switch b {
// case yes: // Error: Use of unresolved identifier 'yes'
// case .yes: // Error: Enum case 'yes' not found in type 'Booly'
// case Booly.yes: // Error: Enum case 'yes' not found in type 'Booly'
//}
let externalYes = Booly.truth
switch b {
case externalYes:
print ("finally, yes!")
default:
()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment