Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 检查是否可以存档NSDictionary后崩溃_Iphone_Objective C_Ios_Xcode_Nskeyedarchiver - Fatal编程技术网

Iphone 检查是否可以存档NSDictionary后崩溃

Iphone 检查是否可以存档NSDictionary后崩溃,iphone,objective-c,ios,xcode,nskeyedarchiver,Iphone,Objective C,Ios,Xcode,Nskeyedarchiver,我使用以下代码创建NSDictionary,然后在存档时检查其所有值(及其本身)是否为零: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *openbook = [defaults objectForKey:@"OpenBookKey"]; NSString *book = [NSString stringWithFormat:@"UploadedWB%@", openbook]; Reac

我使用以下代码创建NSDictionary,然后在存档时检查其所有值(及其本身)是否为零:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *openbook = [defaults objectForKey:@"OpenBookKey"];
NSString *book = [NSString stringWithFormat:@"UploadedWB%@", openbook];

Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus != NotReachable) {

[activityIndicator setHidden:NO];
[activityIndicator startAnimating];

NSLog(@"Sending data to cloud");

NSInteger integer = [[defaults objectForKey:@"CurrentIndex"] integerValue];

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *fileName = [NSString stringWithFormat:@"%@/BVAuthors.txt",
                      documentsDirectory];

NSString *fileName1 = [NSString stringWithFormat:@"%@/BVImages.txt",
                      documentsDirectory];

NSString *fileName2 = [NSString stringWithFormat:@"%@/BVTitles.txt",
                       documentsDirectory];

NSMutableArray *authors = [NSMutableArray arrayWithContentsOfFile:fileName];
NSMutableArray *images = [NSMutableArray arrayWithContentsOfFile:fileName1];
NSMutableArray *titles = [NSMutableArray arrayWithContentsOfFile:fileName2];

NSString *author = [authors objectAtIndex:integer];
UIImage *image = [images objectAtIndex:integer];
NSString *title = [titles objectAtIndex:integer];

NSLog(@"Sending %@ by %@", title, author);

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:_pages, @"pagesarray", _pagessavedbg, @"pagessavedbgarray", author, @"author", image, @"image", title, @"title", nil];

// NSLog(@"DICT: %@", dict);

if([NSKeyedArchiver archivedDataWithRootObject:dict] != NULL)
{

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict];

NSLog(@"Here the data is used, but it crashes before this point");

}

else

{

  NSLog(@"This is never called :(");

}

}
我总是在
[NSKeyedArchiver archivedDataWithRootObject:dict]上崩溃空
,出现以下错误:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x1e8a8fd0> was mutated while being enumerated.'
*** First throw call stack:
(0x38e8c6c3 0x3b0a597f 0x38e8c1a5 0x3b1b0527 0x3b1b02b9 0x3b1af04f 0x3b1b0537 0x3b1ea455 0x3b1af04f 0x3b1ae8f5 0xcfeaf 0x3b24d6bd 0x388dc351 0x388dc218)
libc++abi.dylib: terminate called throwing an exception
(lldb) 
***由于未捕获的异常“NSGenericeException”而终止应用程序,原因:“***集合在枚举时发生了变异。”
***第一次抛出调用堆栈:
(0x38e8c6c3 0x3b0a597f 0x38e8c1a5 0x3b1b0527 0x3b1b02b9 0x3b1af04f 0x3b1b0537 0x3b1ea455 0x3b1af04f 0x3b1ae8f5 0xcfeaf 0x3B24Dbd 0x388dc351 0x388dc218)
libc++abi.dylib:terminate调用引发异常
(lldb)

为什么会发生这种情况?

你是在一个周期内这样做的吗?(暂时还是暂时?)。因为从外观上看:

'*** Collection <__NSArrayM: 0x1e8a8fd0> was mutated while being enumerated.'
“***集合在枚举时发生了变异。”
似乎是这样