No Description

FKIdCardManageViewModel.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // FKIdCardManageViewModel.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/11/25.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKIdCardManageViewModel.h"
  9. @implementation FKIdCardManageViewModel
  10. - (FKIdCardItem *)idCardItemAtIndex:(NSUInteger)index{
  11. if (index < self.idCardArray.count ) {
  12. return self.idCardArray[index];
  13. }
  14. return nil;
  15. }
  16. - (void)setDefaultAtIndex:(NSUInteger)index{
  17. if (index < self.idCardArray.count) {
  18. for (FKIdCardItem *item in self.idCardArray) {
  19. item.isDefault = @"0";
  20. }
  21. FKIdCardItem *targetItem = [self idCardItemAtIndex:index];
  22. if (targetItem) targetItem.isDefault = @"1";
  23. }
  24. }
  25. - (NSUInteger)currentDefaultIndex{
  26. __block NSUInteger index = 0;
  27. [self.idCardArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  28. FKIdCardItem *item = (FKIdCardItem *)obj;
  29. if ([item isKindOfClass:[FKIdCardItem class]] && [item checkIsDefault] == YES) index = idx;
  30. }];
  31. return index;
  32. }
  33. - (void)deleteIdCardAtIndex:(NSUInteger)index{
  34. if (index < self.idCardArray.count) {
  35. NSMutableArray *arrayM = [NSMutableArray arrayWithArray:self.idCardArray];
  36. [arrayM removeObjectAtIndex:index];
  37. self.idCardArray = arrayM;
  38. }
  39. }
  40. @end