0

I defined an objective-C method which expect an arbitrary set of parameters

- (void)logString:(NSString *)format, ... {
    __block va_list argList;
    va_start (argList, format);
    NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:argList];
    va_end(argList);
    NSLog(@"[ProCheck] %@", formattedString);
}

If I call directly this method everything works fine. Now I need to call this method from a method which take the same set of parameters:

- (void)doSomethingAndLogString:(NSString *)format, ... {
    <my code doing something>
    __block va_list argList;
    va_start (argList, format);
    [self logString:format, argsList];
    va_end(argList);
}

But it result in a runtime exception EXC_BAD_ACCESS .

I think I might be wrong with object retain cycle, any clue?

Eric E.
  • 81
  • 3
  • The behavior here is the same as C. You can't do this in general; you must have another version of the function/method you're calling whose parameter type is actually a `va_list`. – jscs Feb 01 '19 at 18:55

1 Answers1

0

Afaik, you can not just simply forward. Suggestion would be to add an additional method which takes va_list as a parameter, something like it:

- (void)logString:(NSString *)format, ...;
- (void)logString:(NSString *)format arguments:(va_list)argList;
Mindaugas
  • 1,707
  • 13
  • 20