1111#import " QMUICore.h"
1212#import " UIScrollView+QMUI.h"
1313#import " UIView+QMUI.h"
14+ #import " NSNumber+QMUI.h"
1415
1516@implementation QMUICellHeightCache {
16- NSMutableDictionary *_mutableHeightsByKeyForPortrait;
17- NSMutableDictionary *_mutableHeightsByKeyForLandscape;
17+ NSMutableDictionary < id < NSCopying >, NSNumber *> *_mutableHeightsByKeyForPortrait;
18+ NSMutableDictionary < id < NSCopying >, NSNumber *> *_mutableHeightsByKeyForLandscape;
1819}
1920
2021- (instancetype )init {
@@ -26,7 +27,7 @@ - (instancetype)init {
2627 return self;
2728}
2829
29- - (NSMutableDictionary *)mutableHeightsByKeyForCurrentOrientation {
30+ - (NSMutableDictionary <id< NSCopying >, NSNumber *> *)mutableHeightsByKeyForCurrentOrientation {
3031 return UIDeviceOrientationIsPortrait ([UIDevice currentDevice ].orientation ) ? _mutableHeightsByKeyForPortrait : _mutableHeightsByKeyForLandscape;
3132}
3233
@@ -40,11 +41,7 @@ - (void)cacheHeight:(CGFloat)height byKey:(id<NSCopying>)key {
4041}
4142
4243- (CGFloat)heightForKey : (id <NSCopying >)key {
43- #if CGFLOAT_IS_DOUBLE
44- return [[self mutableHeightsByKeyForCurrentOrientation ][key] doubleValue ];
45- #else
46- return [[self mutableHeightsByKeyForCurrentOrientation ][key] floatValue ];
47- #endif
44+ return [self mutableHeightsByKeyForCurrentOrientation ][key].qmui_CGFloatValue ;
4845}
4946
5047- (void )invalidateHeightForKey : (id <NSCopying >)key {
@@ -64,8 +61,8 @@ - (NSString *)description {
6461@end
6562
6663@implementation QMUICellHeightIndexPathCache {
67- NSMutableArray *_heightsBySectionForPortrait;
68- NSMutableArray *_heightsBySectionForLandscape;
64+ NSMutableArray < NSMutableArray < NSNumber *> *> *_heightsBySectionForPortrait;
65+ NSMutableArray < NSMutableArray < NSNumber *> *> *_heightsBySectionForLandscape;
6966}
7067
7168- (instancetype )init {
@@ -77,11 +74,11 @@ - (instancetype)init {
7774 return self;
7875}
7976
80- - (NSMutableArray *)heightsBySectionForCurrentOrientation {
77+ - (NSMutableArray <NSMutableArray<NSNumber *> *> *)heightsBySectionForCurrentOrientation {
8178 return UIDeviceOrientationIsPortrait ([UIDevice currentDevice ].orientation ) ? _heightsBySectionForPortrait : _heightsBySectionForLandscape;
8279}
8380
84- - (void )enumerateAllOrientationsUsingBlock : (void (^)(NSMutableArray *heightsBySection))block {
81+ - (void )enumerateAllOrientationsUsingBlock : (void (^)(NSMutableArray <NSMutableArray<NSNumber *> *> *heightsBySection))block {
8582 if (block) {
8683 block (_heightsBySectionForPortrait);
8784 block (_heightsBySectionForLandscape);
@@ -102,36 +99,31 @@ - (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath {
10299
103100- (CGFloat)heightForIndexPath : (NSIndexPath *)indexPath {
104101 [self buildCachesAtIndexPathsIfNeeded: @[indexPath]];
105- NSNumber *number = self.heightsBySectionForCurrentOrientation [indexPath.section][indexPath.row];
106- #if CGFLOAT_IS_DOUBLE
107- return number.doubleValue ;
108- #else
109- return number.floatValue ;
110- #endif
102+ return self.heightsBySectionForCurrentOrientation [indexPath.section][indexPath.row].qmui_CGFloatValue ;
111103}
112104
113105- (void )invalidateHeightAtIndexPath : (NSIndexPath *)indexPath {
114106 [self buildCachesAtIndexPathsIfNeeded: @[indexPath]];
115- [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray *heightsBySection) {
107+ [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray < NSMutableArray < NSNumber *> *> *heightsBySection) {
116108 heightsBySection[indexPath.section][indexPath.row] = @-1 ;
117109 }];
118110}
119111
120112- (void )invalidateAllHeightCache {
121- [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray *heightsBySection) {
113+ [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray < NSMutableArray < NSNumber *> *> *heightsBySection) {
122114 [heightsBySection removeAllObjects ];
123115 }];
124116}
125117
126- - (void )buildCachesAtIndexPathsIfNeeded : (NSArray *)indexPaths {
118+ - (void )buildCachesAtIndexPathsIfNeeded : (NSArray <NSIndexPath *> *)indexPaths {
127119 [indexPaths enumerateObjectsUsingBlock: ^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
128120 [self buildSectionsIfNeeded: indexPath.section];
129121 [self buildRowsIfNeeded: indexPath.row inExistSection: indexPath.section];
130122 }];
131123}
132124
133125- (void )buildSectionsIfNeeded : (NSInteger )targetSection {
134- [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray *heightsBySection) {
126+ [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray < NSMutableArray < NSNumber *> *> *heightsBySection) {
135127 for (NSInteger section = 0 ; section <= targetSection; ++section) {
136128 if (section >= heightsBySection.count ) {
137129 heightsBySection[section] = [NSMutableArray array ];
@@ -141,7 +133,7 @@ - (void)buildSectionsIfNeeded:(NSInteger)targetSection {
141133}
142134
143135- (void )buildRowsIfNeeded : (NSInteger )targetRow inExistSection : (NSInteger )section {
144- [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray *heightsBySection) {
136+ [self enumerateAllOrientationsUsingBlock: ^(NSMutableArray < NSMutableArray < NSNumber *> *> *heightsBySection) {
145137 NSMutableArray *heightsByRow = heightsBySection[section];
146138 for (NSInteger row = 0 ; row <= targetRow; ++row) {
147139 if (row >= heightsByRow.count ) {
0 commit comments