I'm using Typhoon in a Swift project which requires protocols to be marked with @objc. I am attempting to upgrade my project to Swift 2.
In my iOS application, my service layer throws Errors back to the UI. However, despite my best efforts, I get a compile error:
Type 'ErrorThrower' does not conform to protocol 'Throwable'
@objc protocol Throwable {
func doSomething(someParam:AnyObject) throws
}
@objc class ErrorThrower : NSObject, Throwable {
func doSomething(someParam: AnyObject) throws {
NSLog("An error is about to be thrown")
throw GenericError.Generic
}
}
enum GenericError : ErrorType {
case Generic
}
I saw this post "Swift class does not conform to Objective-C protocol with error handling"
So, that made me try something like this:
@objc protocol Throwable {
func doSomething(someParam:AnyObject) throws
}
class ErrorThrower : NSObject, Throwable {
@objc(doSomethingAndReturnError:someParam:)
func doSomething(someParam: AnyObject) throws {
NSLog("An error is about to be thrown")
throw GenericError.Generic
}
}
It doesn't complain about the @objc(...) on the implementation, but it still gives the same non-conforming protocol error.
I also tried this with no luck...
@objc protocol Throwable {
func doSomethingAndReturnError(error:NSErrorPointer, someParam:AnyObject) -> Bool
}
What's the proper way in Swift 2 to declare a protocol with @objc and throw an error on methods?
Unfortunately, from what I researched today, I believe that Swift 2 style exception are incompatible with Objective-C, and therefore will not work with Typhoon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With