I need to create in an iOS application a fake va_list
to pass to a NSString initWithFormat:arguments:
function, this is my code:
NSArray *fixedArguments = [[NSArray alloc] initWithArray:arguments];
NSRange range = NSMakeRange(0, [fixedArguments count]);
va_list fakeArgList = (va_list)malloc(sizeof(NSString *) * [fixedArguments count]);
__unsafe_unretained id *ptr = (__unsafe_unretained id *)fakeArgList;
[fixedArguments getObjects:ptr range:range];
content = [[NSString alloc] initWithFormat:outputFormat
arguments:(va_list)fakeArgList];
free(fakeArgList);
The compiler complains with this message on the cast line:
error: cast of a non-Objective-C pointer type 'va_list' (aka 'char *') to '__unsafe_unretained id *' is disallowed with ARC
The getObjects:range:
function is defined as follows:
- (void)getObjects:(id __unsafe_unretained [])objects range:(NSRange)range;
I've tried everything but still can't get rid of this error...
Is there a solution for creating a fake va_list
with ARC enabled? What am i doing wrong?
"(%@ - %@) %@"
, and a list of keys populates the picker view with the formatted string extracting the data from the plist file. The only way i found to use a formatted print with a variable list of arguments was faking a va_list. I know it's far from being clean programming but i couldn't come up with a better solution, any valid alternative is really welcome and i think i will post another question about my problem to find a cleaner solution. – Marchant