I look at the varargs list, and when I get to the last object in the list, I always get the BAD_ACCESS error. I strongly believe this is an ARC problem.
This is what I do:
-(NSString *)replaceTokensWithStrings:(NSString *)firstKey, ... { va_list _arguments; va_start(_arguments, firstKey); for (NSString *_currentArgument = firstKey; _currentArgument != nil; _currentArgument = va_arg(_arguments, NSString*)) { NSLog(@"%@", _currentArgument); } va_end(_arguments); return nil; }
I need to somehow tell the compiler to save the result returned by va_arg , but I cannot figure out where and how to apply this paradigm.
Update 1: This is how I call my method:
[@"Hello <firstname> <lastname>" replaceTokensWithStrings: @"firstname", @"Peter", @"lastname", "Smith", nil];
Update 2:. I updated my question and added the error I made to show what I actually did wrong. See my answer below.
source share