TDFileStorage.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // TDFileStorage.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/10/10.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDFileStorage.h"
  9. @implementation TDFileStorage
  10. TDShareInstance_implementation(TDFileStorage)
  11. - (void)saveStringDefault:(NSString *)string forKey:(NSString *)key {
  12. [_UD setObject:string forKey:key];
  13. }
  14. - (NSString *)loadStringDefaultFromKey:(NSString *)key {
  15. return [_UD stringForKey:key];
  16. }
  17. - (void)saveArrayDefault:(NSArray *)array forKey:(NSString *)key {
  18. if (array.count) {
  19. [_UD setObject:array forKey:key];
  20. } else {
  21. [_UD removeObjectForKey:key];
  22. }
  23. [[NSUserDefaults standardUserDefaults] synchronize];
  24. }
  25. - (NSArray *)loadArrayDefaultFromKey:(NSString *)key {
  26. NSArray *array = [_UD arrayForKey:key];
  27. if (array.count) {
  28. return array;
  29. }
  30. return @[];
  31. }
  32. /* 首页搜索历史 */
  33. - (void)saveMainSearchArray:(NSArray *)array {
  34. [self saveArrayDefault:array forKey:@"MainSearchHistory"];
  35. }
  36. - (NSArray *)loadMainSearchArray {
  37. return [self loadArrayDefaultFromKey:@"MainSearchHistory"];
  38. }
  39. - (void)saveHistorySearchBySearchType:(HistorySearchType)historySearchType WithArr:(NSArray *)array {
  40. [self saveArrayDefault:array forKey:[NSString stringWithFormat:@"MainSearchHistory-%@",@(historySearchType)]];
  41. }
  42. - (NSArray *)loadHistorySearchBySearchType:(HistorySearchType)historySearchType {
  43. return [self loadArrayDefaultFromKey:[NSString stringWithFormat:@"MainSearchHistory-%@",@(historySearchType)]];
  44. }
  45. @end