// // TDFileStorage.m // TheoryNetwork // // Created by tederen on 2019/10/10. // Copyright © 2019 tederen. All rights reserved. // #import "TDFileStorage.h" @implementation TDFileStorage TDShareInstance_implementation(TDFileStorage) - (void)saveStringDefault:(NSString *)string forKey:(NSString *)key { [_UD setObject:string forKey:key]; } - (NSString *)loadStringDefaultFromKey:(NSString *)key { return [_UD stringForKey:key]; } - (void)saveArrayDefault:(NSArray *)array forKey:(NSString *)key { if (array.count) { [_UD setObject:array forKey:key]; } else { [_UD removeObjectForKey:key]; } [[NSUserDefaults standardUserDefaults] synchronize]; } - (NSArray *)loadArrayDefaultFromKey:(NSString *)key { NSArray *array = [_UD arrayForKey:key]; if (array.count) { return array; } return @[]; } /* 首页搜索历史 */ - (void)saveMainSearchArray:(NSArray *)array { [self saveArrayDefault:array forKey:@"MainSearchHistory"]; } - (NSArray *)loadMainSearchArray { return [self loadArrayDefaultFromKey:@"MainSearchHistory"]; } - (void)saveHistorySearchBySearchType:(HistorySearchType)historySearchType WithArr:(NSArray *)array { [self saveArrayDefault:array forKey:[NSString stringWithFormat:@"MainSearchHistory-%@",@(historySearchType)]]; } - (NSArray *)loadHistorySearchBySearchType:(HistorySearchType)historySearchType { return [self loadArrayDefaultFromKey:[NSString stringWithFormat:@"MainSearchHistory-%@",@(historySearchType)]]; } @end