今天写Http请求缓存的两个小bug

今天写Http请求缓存的两个小bug_第1张图片
  • 异常1
    hello world

Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason:
'-[__NSCFDictionary setObject:forKey:]:
mutating method sent to immutable object'

  • 解决方法:
    将如下代码
NSData   *jsonData = 
[NSJSONSerialization
dataWithJSONObject:dictionary options:
NSJSONWritingPrettyPrinted error:&error];

改成:

NSData *jsonData ;
  if ([NSJSONSerialization isValidJSONObject:dictionary]) {
      jsonData = [NSJSONSerialization         dataWithJSONObject:dictionary
                options:0 error: &error];
      }
  • 异常 2

Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[__NSCFDictionary setObject:forKey:]:
mutating method sent to immutable object'

将如下代码

 NSMutableDictionary *cacheDic = 
[USER_DEFAULT objectForKey:HttpExpiredCacheArrayKey];

改成

NSMutableDictionary *cacheDic =
[NSMutableDictionary dictionaryWithDictionary:
[USER_DEFAULT objectForKey:HttpExpiredCacheArrayKey]];

你可能感兴趣的:(今天写Http请求缓存的两个小bug)