Closed jasperblues closed 10 years ago
We could make requestHeaders
a NSDictionary
instance, and change the following two methods accordingly:
- (void)setHeaderWithName:(NSString *)name value:(NSString *)value {
if(name == nil || value == nil) return;
NSMutableDictionary *md = [_requestHeaders mutableCopy];
[md setObject:value forKey:name];
self.requestHeaders = [NSDictionary dictionaryWithDictionary:md];
}
- (void)removeHeaderWithName:(NSString *)name {
if(name == nil) return;
NSMutableDictionary *md = [_requestHeaders mutableCopy];
[md removeObjectForKey:name];
self.requestHeaders = [NSDictionary dictionaryWithDictionary:md];
}
However, it would break existing code modifying the mutable dictionary.
Also, it wouldn't be consistent to have an immutable dictionary and methods to add and remove headers.
That's why I think it's best if you just convert your dictionary into a mutable one.
This time, I would like to set my request headers like this:
. . rather than use the convenience
request setHeaderWithName:value]
methods.However request headers requires a NSMutableDictionary. I can create a mutable copy, but perhaps it would be even better if this was done internally. Eg: