Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Objective c 从存档文件还原对象_Objective C_Ios_Nskeyedarchiver - Fatal编程技术网

Objective c 从存档文件还原对象

Objective c 从存档文件还原对象,objective-c,ios,nskeyedarchiver,Objective C,Ios,Nskeyedarchiver,我正在使用 [NSKeyedArchiver archiveRootObject:data toFile:file]; 将NSMutableArray保存到文件。那很好 当我试图取回阵列时,问题就出现了 NSMutableArray *s = [NSKeyedUnarchiver unarchiveObjectWithData:file]; 我明白了 Incompatible pointer types sending NSString *__strong to parameter of t

我正在使用

[NSKeyedArchiver archiveRootObject:data toFile:file];
将NSMutableArray保存到文件。那很好

当我试图取回阵列时,问题就出现了

NSMutableArray *s = [NSKeyedUnarchiver unarchiveObjectWithData:file];
我明白了

Incompatible pointer types sending NSString *__strong to parameter of type NSData

这里出了什么问题?

您试图使用
unarchiveObjectWithData:
,它希望您将文件的内容传递给它。尝试改用
unarchiveObjectWithFile:
,它希望您将文件名传递给它

NSData* arrayData = [NSData dataWithContentsOfFile:file];
NSMutableArray* s = [NSKeyedUnarchiver unarchiveObjectWithData:arrayData]
对于生产代码,您应该在假设数据有效之前进行一些类型/空检查