我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
*** First throw call stack:
导致错误的代码是:
NSDictionary *dict = nil;
@synchronized(self) {
dict = [pendingDictionarySaves objectForKey:file];
}
if (dict) return dict;
@synchronized(self) {
dict = [savedDictionaries objectForKey:file];
}
if (dict) return dict;
NSData *plistData = [[NSFileManager defaultManager] contentsAtPath:file];
NSError *error = nil;
if ([[NSPropertyListSerialization class]
respondsToSelector:@selector(propertyListWithData:options:format:error:)]) {
return [NSPropertyListSerialization propertyListWithData:plistData
options:NSPropertyListImmutable
format:NULL
error:&error];
}
基本上原因是因为 plistData 为空。文件路径是:
/Users/aditya15417/Library/Application Support/iPhone Simulator/5.1/Applications/A355D003-668C-4B81-80DC-66C968FE57D3/Library/Caches/NewsfeedCache/?type=news
这是我初始化路径的方式:
NSString *path = [basePath stringByAppendingPathComponent:[streamURL uniqueFileName]];
// Create the directories if needed
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];
}
return path;
问题是如何在不必检查 pListData 是否为空的情况下让它工作?