Skip to content

Instantly share code, notes, and snippets.

@below
Created March 3, 2016 09:33
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 below/41d8425f1274e4a05245 to your computer and use it in GitHub Desktop.
Save below/41d8425f1274e4a05245 to your computer and use it in GitHub Desktop.
Why is the NEHotspotHelperConfidence not nil if out of bounds?
import UIKit
import NetworkExtension
//: First a classical enum. As documented, it will be nil if initialized with a rawValue outside of bounds
//: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Enumerations.html
enum Foobar : Int {
case foo
case bar
}
if let faz = Foobar(rawValue: 4) {
print ("Valid foobar")
}
else {
print ("No foobar")
}
//: Now the NEHotspotHelperConfidence, defined as:
/*
public enum NEHotspotHelperConfidence : Int {
case None
case Low
case High
}
*/
if let confidence = NEHotspotHelperConfidence(rawValue: 120) {
switch (confidence) {
case .None :
print ("None")
case .Low:
print ("Low")
case .High:
print ("High")
}
}
else {
print ("Unknown")
}
// My expected result would be "Unknown", but it is "None". What is going on here? Is this a bug?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment