斯威夫特& Objective C协议:抛出函数声明

时间:2017-04-13 09:48:06

标签: objective-c swift objective-c-protocol

我在库中有一个Obj C协议......

@protocol DataWriter <NSObject>

- (void) writeData:(NSData*)data;

@end

...我想在Swift 3.1中使用:

class Streamer: NSObject, DataWriter {

    ...

    // MARK: - DataWriter

    func write(_ data: Data) throws {
        // write data
        throw NSError(domain: "", code: 1, userInfo: nil)
    }
}

这没有错误抛出工作正常,但在这里编译器抱怨Candidate throws, but protocol does not allow it,我完全得到。我如何更改协议以便在writeData

中抛出错误

0 个答案:

没有答案