You could construct your params string from a dictionary with something like this:
/* Suppose that we got a dictionary with
param/value pairs */
NSDictionary *params = @{
@"sort":@"something",
@"filter":@"aFilter",
@"category":@"aCategory"
};
/* We iterate the dictionary now
and append each pair to an array
formatted like <KEY>=<VALUE> */
NSMutableArray *pairs = [[NSMutableArray alloc] initWithCapacity:0];
for (NSString *key in params) {
[pairs addObject:[NSString stringWithFormat:@"%@=%@", key, params[key]]];
}
/* We finally join the pairs of our array
using the '&' */
NSString *requestParams = [pairs componentsJoinedByString:@"&"];
If you log the requestParams
string you will get:
filter=aFilter&category=aCategory&sort=something
PS I totally agree with @rckoenes that AFNetworking
is the best solution for this kind of operations.