[swift-users] Handle deprecated enum cases from a library

Charles Srstka cocoadev at charlessoft.com
Sun Nov 5 09:13:22 CST 2017


> On Nov 5, 2017, at 3:14 AM, Dennis Weissmann <dennis at dennisweissmann.me> wrote:
> 
> Hi Charles,
> 
> You are right (the `default` case would not catch the deprecated values but only new ones introduced in future releases), but the compiler doesn’t seem to know that :(
> 
> But now that you say it, one approach could be to pattern match the raw values (and, well, have a default clause, which I really want to avoid) 🤔
> 
> - Dennis
> 
> Sent from my iPhone

Hi Dennis,

What I am saying is that the new cases have the same raw values as the old ones. touchIDNotAvailable is -6; biometryNotAvailable is -6. touchIDNotEnrolled is -7; biometryNotEnrolled is -7. touchIDLockout it -8; biometryLockout is -8. They’re just aliases to each other, so if you handle one, you don’t have to handle the other. You can literally ignore the deprecated values and treat them as if they don’t exist. Try this code for yourself if you don’t believe me:

let err = LAError.touchIDLockout

switch err {
case LAError.biometryLockout:
	print("biometry lockout")
default:
	print("default")
}

This prints “biometry lockout”.

Charles



More information about the swift-users mailing list