model存取

反归档 转为Model类型
+ (SAForumDisplayModel *)communityModelWithKey:(NSString *)key {
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (![defaults objectForKey:key]) {
        return nil;
    }
    
    NSData* data  = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    SAForumDisplayModel * mode = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    
    return mode;
}

归档 转为二进制流
+ (void)setCommunityModel:(SAForumDisplayModel *)newCommunityModel Key:(NSString *)key{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[NSKeyedArchiver archivedDataWithRootObject:newCommunityModel] forKey:key];
}

你可能感兴趣的:(model存取)