COSMO BAKER
COSMO BAKER

Reputation: 457

Objective-C Method Parameters in Swift

Having some issues calling a method declared in Objective-C and bridged into Swift. I created a void method right next to the one in question and am able to call it, so I'm pretty certain it has to do with the way the bridging is handling the method's parameters.

- (void)foo;

- (NSArray *)fetchProductHistoryForProduct:(Product *)product
                               forCustomer:(Customer *)customer
                                  forField:(Field *)field
                                  forRange:(DatePickerRange *)range
                                 inContext:(CPSPersistenceController *)context;

Then in the Swift file I am calling each like this:

modelUtil.foo()

let result = modelUtil.fetchProductHistoryForProduct(product, forCustomer: nil, forField: nil, forRange: nil, inContext: nil)

Swift complains "Value of type 'ModelUtil' has no member 'fetchProductHistoryforProduct'"

Could you tell me what I'm doing wrong?

Upvotes: 1

Views: 210

Answers (2)

vacawama
vacawama

Reputation: 154691

You can use Xcode autocompletion to find the calling sequence. In this case, the forProduct: becomes the label for the first parameter:

let result = modelUtil.fetchProductHistory(forProduct: product, forCustomer: nil, forField: nil, forRange: nil, inContext: nil)

Upvotes: 1

rounak
rounak

Reputation: 9397

You can see the generated interface for the objective c file from the top left corner of the editor window. The generated interface is like a Swift header file for your ObjC file that should tell you the exact name of the method. Also make sure that all the files containing the parameter types are also added to the bridging-header.

Upvotes: 1

Related Questions