Using NSKeyedArchiver to store custom data model

后端 未结 3 1903
星月不相逢
星月不相逢 2021-02-06 00:45

I\'m working on a rss reader. It is just a tableview and each cell shows a custom data model RSSEntry. And I have a NSMutableArray allEntries which contains all RSSEntry I got f

3条回答
  •  情歌与酒
    2021-02-06 00:59

    For iOS 12:

    for archivedDataWithRootObject:

    NSData *myDicData = [NSKeyedArchiver archivedDataWithRootObject:AllDataDic 
                                         requiringSecureCoding:YES error:nil];
    [[NSUserDefaults standardUserDefaults] setObject:myDicData forKey:@"Yourkey"];
    

    for unarchivedObjectOfClass:

    NSData *tempData = [[NSUserDefaults standardUserDefaults] valueForKey:@"Yourkey"];
    NSDictionary *myDicProfile = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSDictionary class] 
                                                    fromData:tempData error:nil];
    

提交回复
热议问题