NEHotspotConfigurationError is an error code, not an Error, and so doesn't allow pattern matching in Swift
Originator: | brandon | ||
Number: | rdar://37604384 | Date Originated: | 2018/02/16 |
Status: | Open | Resolved: | |
Product: | Network Extensions Framework | Product Version: | iOS 11 |
Classification: | Suggestion | Reproducible: |
What I'd like to be able to do: NEHotspotConfigurationManager.shared.apply(config) { possibleError in if let error = possibleError { switch error { case NEHotspotConfigurationError.alreadyAssociated: // ... case NEHotspotConfigurationError.pending: // ... default: // ... } } } This is similar to other error types like URLError, which make use of NS_ERROR_ENUM: https://twitter.com/kostaskremizas/status/923228453784170497 This would also allow catching NEHotspotConfigurationError from throwing functions. There aren't any in the NEHotspotConfigurationManager API right now, but these could be thrown from user-created functions that wrap it, or come from future first-party APIs. https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html#//apple_ref/doc/uid/TP40014216-CH7-ID223 What I currently have to do: NEHotspotConfigurationManager.shared.apply(config) { possibleError in if let error = possibleError { let nsError = error as NSError if nsError.domain == "NEHotspotConfigurationErrorDomain" { switch nsError.code { case NEHotspotConfigurationError.alreadyAssociated.rawValue: // ... case NEHotspotConfigurationError.pending.rawValue: // ... default: // ... } return } } }
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!