Obj-C method with NSError** doesn't become throwable in Swift

I'm trying to write a method like this:

- (NSData*) createFOO (NSError**) outError;

Unfortunately, when I reference this from Swift like so:

let data = obj.createFOO()

The compiler (Xcode 11b7) complains:

File.swift:849:33: Missing argument for parameter #1 in call
/__ObjC.MyObjCObj:7:15: 'createFOO' declared here

And it offers the fix-it Insert '<#NSErrorPointer#>'. It should instead complain that the call throws. I wonder if this is because the error isn't a separate error: parameter, but I don't have any other parameters that need to be sent. Am I missing something?

This happens if your return type is non-nullable. Is your declaration surrounded with NS_ASSUME_NONNULL_BEGIN/_END?

4 Likes

Ah, yes, that was it. This fixed it:

- (NSData* _Nullable) createFOO (NSError**) outError;
Terms of Service

Privacy Policy

Cookie Policy