Swift 2 - @objc protocol that causes an error

I use Typhoon in a Swift project that requires protocols to be tagged with @objc. I am trying to upgrade my project to Swift 2.

In my iOS application, my service level throws Errors back to the user interface. However, despite all my efforts, I get a compilation error:

Type "ErrorThrower" does not comply with the 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 the Swift class does not conform to the Objective-C error handling protocol "

So this 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
    }
}

He does not complain about @objc (...) for the implementation, but still gives the same inappropriate protocol error.

I also tried this with no luck ...

@objc protocol Throwable {
    func doSomethingAndReturnError(error:NSErrorPointer, someParam:AnyObject) -> Bool
}

Swift 2 @objc ?

+4
1

, , , , Swift 2 Objective-C Typhoon.

+2

All Articles