4

My code currently looks like this

NSURL *URL = [NSURL URLWithString:URLForSend];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
                                     initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"%@", responseObject);
     [BoxJsonDataHelper gotNewJson:responseObject];
 } failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@"Request Failure Because %@",[error userInfo]);
 }];

[operation start];

But when trying to edit dictionaries in object received, I get an error about using methods that belongs to a mutable dictionary rather than a dictionary. How do I make AFNetworking use nested mutable objects instead?

Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43
  • Possible duplicate of [How do you get mutable dictionaries from AFNetworking and AFJSONRequestOperation?](http://stackoverflow.com/questions/9409760/how-do-you-get-mutable-dictionaries-from-afnetworking-and-afjsonrequestoperation) – Leena Nov 23 '15 at 11:22

1 Answers1

23

You tell the AFJSONResponseSerializer that it needs to return mutable containers:

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

It is all very well documented: http://cocoadocs.org/docsets/AFNetworking/2.0.0/

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • Thank, I understood wrong from the documentation that it is suppose to be the default. – Yoav Schwartz Nov 15 '13 at 16:54
  • 1
    BTW this option optimizes a bit memory handling, because it doesn't copy mutable container into immutable one. And to return also mutable leaves: manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves]; – Borzh Oct 13 '15 at 12:46