1

I create two function with ObjectiveC, like:

- (void)showName:(NSString *)name, ...;
- (void)showTitle:(NSString *)title;

I can call showTitle: in my swift code, but can't compile if call showName:

Here is my code:

//Objective_C code:
@interface DemoObject : NSObject

- (void)showName:(NSString *)name, ...;
- (void)showTitle:(NSString *)title;

@end

@implementation DemoObject
- (void)showName:(NSString *)name, ... {
NSLog(@"name=%@", name);
}

- (void)showTitle:(NSString *)title {
[self showName:title, @""];
}
@end

//Swift Code:
var obj = DemoObject()
obj.showTitle("");
obj.showName(""); //compile error here

How to fix this problem. Because I use a third library, it contains Variable parameters functions.

Haven Tang
  • 11
  • 2

1 Answers1

4

Swift does not import C functions or Objective-C methods with varargs.

Any good API that has varargs functions also has an alternative form of the function that takes a va_list (e.g. printf has vprintf); or else it has an easy way to achieve the same thing by adding the arguments one by one.

newacct
  • 119,665
  • 29
  • 163
  • 224
  • I +'ed this and I can confirm that it looks like Swift does indeed not support this. The auto complete does not even show the proper function signature and if you try to manually add the extra parameter, then the App will not even compile. – asiby Apr 09 '15 at 14:18