I now try to update my app. and saw unarchiveobjectwithdata:' is deprecated. How i can fix it?
I have class
@interface Favorite : NSObject <NSSecureCoding> //NSCoding NSSecureCoding
@property (nonatomic) NSDate *wikiDate;
@property (nonatomic) FavoriteType type;
- (id) initWithDate:(NSDate *) date type:(FavoriteType) type;
- (id) initNilFavorite;
- (BOOL) isNilFavorite;
- (id) initWithCoder:(NSCoder *)aDecoder;
- (void) encodeWithCoder:(NSCoder *)aCoder;
@end
and i have second class
@interface Settings : NSObject
+ (Settings *) sharedInstance;
@property (nonatomic) NSMutableArray *favorites;
// favorites part
- (BOOL) isFavorite:(NSDate *) date type:(FavoriteType) type;
- (void) addToFavorites:(NSDate *) date type:(FavoriteType) type;
- (void) removeFromFavorites:(NSDate *) date type:(FavoriteType) type;
- (void) groupFavorites;
- (void) saveSettings;
@end
when i save favorite in settigns
- (void) saveFavorites{
NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"favorites"];
NSError* error;
NSData* codedData = [NSKeyedArchiver archivedDataWithRootObject:self.favorites requiringSecureCoding:NO error:&error];
if(error!=nil) {
NSLog(@"Eror when try to archive favorites!!!!");
}
else {
[codedData writeToFile:filePath atomically:YES];
}
}
and i try to load
- (void) loadFavorites{
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"favorites"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
if (data) {
self.favorites = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
}
All working, but now i must to replace unarchiveObjectWithData to unarchivedArrayOfObjectsOfClass
self.favorites is MuttableArray of Favorite class!
I tryed veriants:
NSSet *allowedClasses = [NSSet setWithObjects:[NSMutableArray class],[Favorite class], nil];
NSMutableArray *encodedData = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowedClasses fromData:data error:&error];
and
NSData *encodedData = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSArray class] fromData:data error:&error];
and
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:&error];
[unarchiver setRequiresSecureCoding:NO];
[unarchiver decodeObjectOfClass:[Favorite class] forKey:@""];
[unarchiver finishDecoding];
noting to work :(
Please help me