Avt
Avt

Reputation: 17043

Swift 2: Strange Objective C -> Swift method's signature conversion

I have a base class in Objective-C with the following method:

- (BOOL)canFinishWithError:(NSError *__autoreleasing *)error

when I try to override it in child class using Swift compiler forces me to declare this method without a return value:

override func canFinish() throws{
        // some code
        try super.canFinish()
    }

and not allows me to return something.

enter image description here

How can I return a value from this method? Is it a Swift 2/Xcode 7 beta issue and I should wait for release?

Upvotes: 2

Views: 484

Answers (1)

idmean
idmean

Reputation: 14895

No, it’s not a bug.

Swift 2 automatically recognizes method signatures which can be converted to use try.

A method returning bool and taking a pointer to a NSError pointer is automatically converted to a signature using throw.

You can learn more about that in this WWDC talk: (from 32:00) https://developer.apple.com/videos/wwdc/2015/?id=106

Upvotes: 3

Related Questions