NSMutableArray * array;
array = [NSKeyedUnarchiver unarchiveObjectWithFile: mypath];
可以。
NSData * data = [NSData dataWithContentsOfFile: mypath];
array = [NSKeyedUnarchiver unarchiveObjectWithData: data];
可以。
我不能使用的方法是:
来自日期的+ UnarchivedObjectOfClass:
:错误:
@interface Magazzino: NSObject <NSCoding> {
NSNumber * num;
NSString * description;
NSString * um;
NSNumber * price list;
NSNumber * discount;
NSNumber * cost;
NSNumber * price increase;
}
NSMutableArray * array;
array = [NSKeyedUnarchiver unarchivedObjectOfClass: Magazzino.class fromData: data error: & error];
错误域= NSCocoaErrorDomain代码= 4864“键'root'的值是意外类'NSMutableArray'。允许的类是'{( 马加兹诺
答案 0 :(得分:0)
我发现您必须在NSSet中包括NSString和NSNumber以及主类。
例如
NSSet *classesSet = [NSSet setWithObjects:[NSString class], [SurveyInfo class], [SurveyData class], [PlotInfo class], [DepthRange class], [SurveyLegData class], [ToolfaceData class], [WellboreGeometry class], [WellboreGeometryItem class], [AxisTitles class], [AxisLabels class], [AxisDimensions class], [TextStyle class], [Cell class], [UIFont class], [UIColor class], [NSArray class], [NSMutableArray class], [NSMutableData class], [NSDictionary class], [NSDate class], [NSValue class], [NSNull class], nil];
NSArray *dataArray = (NSArray*)[NSKeyedUnarchiver unarchivedObjectOfClasses: classesSet fromData: unarchivedData error: &error];
我现在唯一的问题是泄漏。