0

I have a NSMutableArray that is set based on selections the user makes. I am than trying to pass that to a NSDictionary that is set to my parameter to be sent to my server. I want to than grab those values placed inside the parameters.

Heres what I am doing:

NSMutableArray: is being set by the following: [_selectedCells addObject:label.text];

NSDictionary *dictionary = @{ @"title": _titlefor.text, 
@"description": _description.text, 
@"time_limit": _timeLimit.date, @"toWho": @""};

toWho is where I want to send the values the user selected.

I've tried something like,[dictionary setValue:self.viewControllers.selectedCells forKey:@"toWho"]; But this does not work correctly.

I think I will have to use a NSMutableDictionary but can I send this to parameters to be sent to my server?

Heres how I am adding parameters:

 NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"downloadFileChallange.php" parameters:dictionary constructingBodyWithBlock:^(id <AFMultipartFormData>formData)
 {
   [formData appendPartWithFileData:webData name:@"file" fileName:newUsername mimeType:@"video/quicktime" ];
 }];

Suggestions, thoughts?

5
  • You'll definitely need to use a mutable dictionary if you're going to set values in it or add values to it. I don't understand the second part of the question, though, so I don't have an answer for that. Commented Apr 18, 2014 at 2:19
  • @user1118321 What do you not understand about it? Commented Apr 18, 2014 at 2:20
  • I've not used NSMutableURLRequest before, so I don't know if just setting the parameters parameter to the dictionary will work. Sorry! Commented Apr 18, 2014 at 2:23
  • You can use an NSMutableDictionary anywhere where an NSDictionary would be accepted. Commented Apr 18, 2014 at 2:50
  • @DavidBiga why are you using _description and _timeLimit instead of self.description and self.timeLimit? It's wrong. Commented Apr 18, 2014 at 3:05

1 Answer 1

1

Yes you can use a dictionary as the parameters of a HTTP request.

I would not give it a mutable dictionary however. Make a copy of it instead, so change the line to:

... parameters:dictionary.copy ...

Have a quick look at the documentation for copy, you'll see that making a "copy" of a mutable object always returns an immutable version of the object. So it will be an NSDictionary, which is what NSMutableURLRequest expects to receive.

The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.