Vlad Papko
Vlad Papko

Reputation: 13302

Swift doesn't see Objective-C methods with variable arguments

I created Objective-C class with two methods. Both of them works with variable list of arguments:

@interface TestClass : NSObject

- (void)methodWithVariableArguments:(NSString *)string  arguments:(va_list)arguments;

- (void)methodWithVariableArguments:(NSString *)string, ...;

@end

When I try to use methods of this class in Swift code, it allows me to use only first method:

var testObject = TestClass()
testObject.methodWithVariableArguments("String", arguments: pointer)

The second one Swift can't recognize.
If I try to navigate to TestClass from Swift code, it shows me this:

class TestClass : NSObject {

    func methodWithVariableArguments(string: String!, arguments: CVaListPointer)
}

It just ignored my second method.
NSString has similar methods and both of them work in Swift.

Does anybody know how to fix it?

Update
I sent bug report to Apple. They confirmed that they have such problem.
Ticket id is 21848465. It was marked as duplicate to ticket with id 15935999. The last on has "Open" status.

Upvotes: 2

Views: 678

Answers (1)

s1ddok
s1ddok

Reputation: 4654

It is simply impossible now. Swift can't do that. Workaround is to create a wrapper method with (va_list) arguments and pass them as arguments. If it is not your class, you could create a category or else just add it to your source.

Upvotes: 3

Related Questions