2

I have a Obj C protocol in a library...

@protocol DataWriter <NSObject>

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

@end

...that I would like to use in Swift 3.1:

class Streamer: NSObject, DataWriter {

    ...

    // MARK: - DataWriter

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

This works fine without the error throwing, but here the compiler complains that Candidate throws, but protocol does not allow it, which I totally get. How would I have to change the protocol so I can throw an error in writeData?

doubleL
  • 21
  • 3
  • 1
    Just a guess, but maybe add an `error:(NSError **)error` parameter to the end of the signature? – Eimantas Apr 13 '17 at 09:49
  • @Eimantas yes, and it also needs to return a bool in the protocol, but not in the swift implementation. `- (BOOL) writeData:(NSData*)data error:(NSError **)error;`seems to work. – doubleL Apr 13 '17 at 10:28

0 Answers0