Gar*_*lph 13 objective-c variadic-functions automatic-ref-counting
我们今天有一些代码接受NSArray并将其作为参数列表传递给 - [NSString initWithFormat:arguments],我们试图让它与ARC一起工作.这是代码使用的
NSString* format = @"Item %s and Item %s"; // Retrieved elsewhere
NSArray* args = [NSArray arrayWithObjects:@"1", @"2", nil]; // Retrieved elsewhere
// http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
char* argsList = (char*) malloc(sizeof(NSString*) * args.count);
[args getObjects:(id*) argsList];
NSString* message = [[[NSString alloc] initWithFormat:format arguments:argsList] autorelease];
free(argsList);
Run Code Online (Sandbox Code Playgroud)
有关如何使ARC符合要求的任何建议?或者我们甚至愿意接受更好的方式.