Bez popisu

FKHotSaleViewModel.m 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // FKHotSaleViewModel.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 2017/6/10.
  6. // Copyright © 2017年 FirstLink. All rights reserved.
  7. //
  8. #import "FKHotSaleViewModel.h"
  9. @implementation FKHotSaleViewModel
  10. - (NSArray *)sectionTitles {
  11. NSMutableArray *array = [NSMutableArray array];
  12. for (FKHotSaleCategoryModel *model in self.categoryArray) {
  13. [array addObject:model.name];
  14. }
  15. return array;
  16. }
  17. - (NSArray<FKHotSaleModel *> *)hotSaleModelArrayWithSectionIndex:(NSInteger)index {
  18. if (index < self.categoryArray.count) {
  19. FKHotSaleCategoryModel *category = self.categoryArray[index];
  20. return self.hotSaleDict[category.cID];
  21. }
  22. return nil;
  23. }
  24. - (void)appendHotSaleList:(NSArray<FKHotSaleModel *> *)array {
  25. FKHotSaleModel *model = array.firstObject;
  26. if (model) {
  27. NSMutableArray *mutArray = [self.hotSaleDict valueForKey:model.cID];
  28. if (mutArray == nil) {
  29. mutArray = [NSMutableArray array];
  30. }
  31. [mutArray addObjectsFromArray:array];
  32. [self.hotSaleDict setValue:mutArray forKey:model.cID];
  33. }
  34. }
  35. - (void)resetHotSaleList:(NSArray<FKHotSaleModel *> *)array {
  36. FKHotSaleModel *model = array.firstObject;
  37. if (model) {
  38. NSMutableArray *mutArray = [NSMutableArray array];
  39. [mutArray addObjectsFromArray:array];
  40. [self.hotSaleDict setValue:mutArray forKey:model.cID];
  41. }
  42. }
  43. #pragma mark - Property
  44. - (NSMutableDictionary<NSString *, NSMutableArray<FKHotSaleModel *> *> *)hotSaleDict {
  45. if (!_hotSaleDict) {
  46. _hotSaleDict = [NSMutableDictionary dictionary];
  47. }
  48. return _hotSaleDict;
  49. }
  50. @end