-
Notifications
You must be signed in to change notification settings - Fork 956
Swift 2.0 Error Handling Compatibility #112
Comments
Fixes issue #112 involving Swift 2.0 error handling compatibility.
Thanks @lgauthier for the update... Can you give an example of how to implement the new error handling method for SSKeychain with Swift 2.0? |
@Razinsky with the change I added, you would use the methods the same way as you normally would with the inout NSError pointer:
In order to use the new Swift 2.0 error handling mechanism, the method declaration that doesn't include the inout NSError pointer would need to be removed. If it's removed, then that would allow this method:
To be converted to this in Swift 2.0:
Then, you could use the method like this:
Unfortunately, if we just removed the method declarations that don't include the inout NSError parameter, we'd lose backwards compatibility for Objective-C code that calls those methods. So, it might be best to remove those method declarations in the next major release. |
Is it possible that the same changes should apply to methods in SSKeychainQuery? |
Though SSKeychainQuery does have methods with an inout NSError parameter, it doesn't have the conflict issue because there aren't alternative versions of the methods that exclude the inout NSError parameter. For those methods, you can use the do-try-catch syntax in Swift 2.0:
|
Thanks a lot man! |
No problem! |
Method declaration is...
|
Right now, there are compatibility issues with Swift 2.0's new error handling system. With the new system, legacy code that follows Cocoa's inout NSError pattern are automatically converted into methods that throw and don't include the inout NSError parameter.
I think the issue that SSKeychain is suffering from stems from the fact that many of the methods provide an alternative method signature without the inout NSError parameter. For example:
For Swift 2.0, these methods get converted to:
So, if you exclude the error parameter in your method call, the compiler will match the method signature with the first method which doesn't throw. I found that I can actually call the second method by including the error parameter with an argument of
()
. However, Xcode still gives the warning, "No calls to throwing functions occur within 'try' expression."I think the best solution (for now) might be to include an annotation in the method declaration similar to the LocalAuthentication framework. An example from the LocalAuthentication framework:
This causes the method to be converted to:
This allows the method to be called with the familiar inout NSError syntax. So the SSKeychain methods could be declared as:
I haven't tested this yet, but I wanted to at least bring it to your attention as early as possible.
The text was updated successfully, but these errors were encountered: