2

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure that it's impossible? Do you have any proof? I am asking because NSString has the same methods, and it perfectly recognized in Swift.
NSString has Swift's methods with a list of arguments, not obj-c ones. Swift also has the feature of argument list, but it is not compatible with obj-c.
you was right. I sent bug report to Apple, they confirmed that they have such bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.