简体   繁体   中英

Swift can't find objc function that with Variable parameters

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.

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 (eg printf has vprintf ); or else it has an easy way to achieve the same thing by adding the arguments one by one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM