Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i build a URL with same key multiple times?

I'm building an iOS app that makes GET requests to a URL. For all the requests it makes, I build the url off a base URL and than add parameters using NSDictionary Key-Value_pairs.

I also use AFNetworking 2.0 to make the request - it builds the URL as well, with the NSDictionary keys supplied.

I have now run into a problem, where a web service I need to use, requires multiple keys to be the same, with different values. This functionality is not possible with NSDictionary

Which means I cannot run the web service successfully.

Here is an example of what I need the finally URL to look like -

http://demo.domain.net/services/.....&IncludedUserIds=12345&IncludedUserIds=2345

The italic bit of the above URL is what I am trying to build using AFNetworking and NSDictionary. I suspect I will have to use something a little more advanced than NSDictionary to pull this off.

Does anyone have any ideas?

Edit

Found a half solutions if I set my NSDictionary Parameters like this with NSSet:

    [self.parameters setObject:[NSSet setWithObjects:@"12345",@"2345", nil] forKey:@"IncludedUserIds"];

This works as I need it to. However I have a follow up question:

The values need to be dynamically added to NSSet - how do I create an NSSet that can accept extra values at runtime?

like image 363
Robert J. Clegg Avatar asked Apr 14 '14 12:04

Robert J. Clegg


1 Answers

I managed to solve this issue:

I just created objects in my NSDictionaray like so:

    [self.myDictionary setObject:[NSSet setWithArray:self.myArray] forKey:@"myKeyNeeded];

The array has NSString objects in it and this seems to work perfectly. I used array instead of NSMutableSet due needing to remove objects easily enough from the NSDictionary.

like image 89
Robert J. Clegg Avatar answered Sep 30 '22 10:09

Robert J. Clegg