我的函数接受一个字典参数和一个可变数量的NSString
变量。所有这些组合都放在一个[NSString stringWithFormat:]
方法中,并以NSURLRequest
. 该方法如下所示:
- (NSURLRequest *)buildPath:(NSString *)stringPath attributes:(NSString *)attribute, ...
{
va_list list;
NSString *eachObject;
NSMutableArray *args = [NSMutableArray array];
[args addObject:attribute];
va_start(list, attribute);
while ((eachObject = va_arg(list, NSString *))) {
[args addObject:eachObject];
}
va_end(list);
NSString *listOfAttributes = [args componentsJoinedByString:@", "];
NSString *pathURL = _requestString[stringPath];
NSString *path = [NSString stringWithFormat:pathURL, listOfAttributes];
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
return request;
}
这是我调用该方法时的样子:
NSURLRequest *request = [_venueService buildPath:@"categories"
attributes:_venueService.clientID, _venueService.clientSecret, _venueService.todaysDate, nil];
当我运行程序时,它崩溃了。当我注销时,listOfAttributes
它给了我:
client_id, client_secret, 20140507
这是我的 3 个参数,这是正确的,并且stringPath
(当我在我编写的程序中实际调用它时stringPath[@"categories"]
)当我 NSLog 给我时:
https://api.foursquare.com/v2/venues/categories?client_id=%@&client_secret=%@&v=%@
所以,我的问题是,为什么这两个字符串会结合在一起[NSString stringWithFormat:]
导致问题?
任何帮助将不胜感激!