Skip to content

Commit 767ecbe

Browse files
committed
Code style, comments, remove nullable
1 parent 8082514 commit 767ecbe

13 files changed

+112
-153
lines changed

Classes/UITableView+FDTemplateLayoutCell.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#import <UIKit/UIKit.h>
2424
#import "UITableView+FDTemplateLayoutCellDebug.h"
2525

26-
NS_ASSUME_NONNULL_BEGIN
27-
28-
typedef void (^__nullable FDTemplateLayoutCellConfigurationBlock)(id cell);
29-
3026
@interface UITableView (FDTemplateLayoutCell)
3127

3228
/// Returns height of cell of type specifed by a reuse identifier and configured
@@ -43,7 +39,7 @@ typedef void (^__nullable FDTemplateLayoutCellConfigurationBlock)(id cell);
4339
/// to the template cell. The configuration should be minimal for scrolling
4440
/// performance yet sufficient for calculating cell's height.
4541
///
46-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(FDTemplateLayoutCellConfigurationBlock)configuration;
42+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(void (^)(id cell))configuration;
4743

4844
/// This method does what "-fd_heightForCellWithIdentifier:configuration" does, and
4945
/// calculated height will be cached by its index path, returns a cached height
@@ -55,11 +51,16 @@ typedef void (^__nullable FDTemplateLayoutCellConfigurationBlock)(id cell);
5551
///
5652
/// @param indexPath where this cell's height cache belongs.
5753
///
58-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(FDTemplateLayoutCellConfigurationBlock)configuration;
54+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration;
5955

60-
/// TODO: +7
56+
/// This method caches height by your model entity's identifier.
57+
/// If your model's changed, call "- invalidateHeightForKey:(id <NSCopying>)key" to
58+
/// invalidate cache and re-calculate, it's much cheaper and effective than
59+
/// "cacheByIndexPath" version.
6160
///
62-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByKey:(id<NSCopying>)key configuration:(FDTemplateLayoutCellConfigurationBlock)configuration;
61+
/// @param key model entity's identifier whose data configures a cell.
62+
///
63+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByKey:(id<NSCopying>)key configuration:(void (^)(id cell))configuration;
6364

6465
@end
6566

@@ -79,13 +80,9 @@ typedef void (^__nullable FDTemplateLayoutCellConfigurationBlock)(id cell);
7980

8081
/// Enable to enforce this template layout cell to use "frame layout" rather than "auto layout",
8182
/// and will ask cell's height by calling "-sizeThatFits:", so you must override this method.
82-
/// Note:
83-
/// If no layout constraints have been added to cell's content view, it will automatically
84-
/// switch to "frame layout" mode. Use this property only when you want to manually control
85-
/// this template layout cell's height calculation mode. Default to NO.
83+
/// Use this property only when you want to manually control this template layout cell's height
84+
/// calculation mode, default to NO.
8685
///
8786
@property (nonatomic, assign) BOOL fd_enforceFrameLayout;
8887

8988
@end
90-
91-
NS_ASSUME_NONNULL_END

Classes/UITableView+FDTemplateLayoutCell.m

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222

2323
#import "UITableView+FDTemplateLayoutCell.h"
2424
#import "UITableView+FDTemplateLayoutCellHeightCache.h"
25-
#import "UITableView+FDTemplateLayoutCellAutoInvalidate.h"
25+
#import "UITableView+FDTemplateLayoutCellInvalidation.h"
2626
#import "UITableView+FDTemplateLayoutCellPrecache.h"
2727
#import <objc/runtime.h>
2828

2929
@implementation UITableView (FDTemplateLayoutCell)
3030

31-
- (id)fd_templateCellForReuseIdentifier:(NSString *)identifier
32-
{
31+
- (id)fd_templateCellForReuseIdentifier:(NSString *)identifier {
3332
NSAssert(identifier.length > 0, @"Expect a valid identifier - %@", identifier);
3433

3534
NSMutableDictionary *templateCellsByIdentifiers = objc_getAssociatedObject(self, _cmd);
@@ -52,8 +51,7 @@ - (id)fd_templateCellForReuseIdentifier:(NSString *)identifier
5251
return templateCell;
5352
}
5453

55-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier configuration:(FDTemplateLayoutCellConfigurationBlock)configuration
56-
{
54+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(void (^)(id cell))configuration {
5755
if (!identifier) {
5856
return 0;
5957
}
@@ -134,8 +132,7 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier confi
134132
return fittingSize.height;
135133
}
136134

137-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier cacheByIndexPath:(NSIndexPath * __nonnull)indexPath configuration:(FDTemplateLayoutCellConfigurationBlock)configuration
138-
{
135+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration {
139136
if (!identifier || !indexPath) {
140137
return 0;
141138
}
@@ -176,8 +173,7 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier cache
176173
return height;
177174
}
178175

179-
- (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier cacheByKey:(id<NSCopying> __nonnull)key configuration:(FDTemplateLayoutCellConfigurationBlock)configuration
180-
{
176+
- (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByKey:(id<NSCopying>)key configuration:(void (^)(id cell))configuration {
181177
if (!identifier || !key) {
182178
return 0;
183179
}
@@ -200,23 +196,19 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString * __nonnull)identifier cache
200196

201197
@implementation UITableViewCell (FDTemplateLayoutCell)
202198

203-
- (BOOL)fd_isTemplateLayoutCell
204-
{
199+
- (BOOL)fd_isTemplateLayoutCell {
205200
return [objc_getAssociatedObject(self, _cmd) boolValue];
206201
}
207202

208-
- (void)setFd_isTemplateLayoutCell:(BOOL)isTemplateLayoutCell
209-
{
203+
- (void)setFd_isTemplateLayoutCell:(BOOL)isTemplateLayoutCell {
210204
objc_setAssociatedObject(self, @selector(fd_isTemplateLayoutCell), @(isTemplateLayoutCell), OBJC_ASSOCIATION_RETAIN);
211205
}
212206

213-
- (BOOL)fd_enforceFrameLayout
214-
{
207+
- (BOOL)fd_enforceFrameLayout {
215208
return [objc_getAssociatedObject(self, _cmd) boolValue];
216209
}
217210

218-
- (void)setFd_enforceFrameLayout:(BOOL)enforceFrameLayout
219-
{
211+
- (void)setFd_enforceFrameLayout:(BOOL)enforceFrameLayout {
220212
objc_setAssociatedObject(self, @selector(fd_enforceFrameLayout), @(enforceFrameLayout), OBJC_ASSOCIATION_RETAIN);
221213
}
222214

Classes/UITableView+FDTemplateLayoutCellDebug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
/// Helps to debug or inspect what is this "FDTemplateLayoutCell" extention doing,
2828
/// turning on to print logs when "creating", "calculating", "precaching" or "hitting cache".
2929
///
30-
/// Default to "NO", log by "NSLog".
30+
/// Default to NO, log by NSLog.
3131
///
3232
@property (nonatomic, assign) BOOL fd_debugLogEnabled;
3333

3434
/// Debug log controlled by "fd_debugLogEnabled".
35-
- (void)fd_debugLog:(nullable NSString *)message;
35+
- (void)fd_debugLog:(NSString *)message;
3636

3737
@end

Classes/UITableView+FDTemplateLayoutCellDebug.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@
2525

2626
@implementation UITableView (FDTemplateLayoutCellDebug)
2727

28-
- (BOOL)fd_debugLogEnabled
29-
{
28+
- (BOOL)fd_debugLogEnabled {
3029
return [objc_getAssociatedObject(self, _cmd) boolValue];
3130
}
3231

33-
- (void)setFd_debugLogEnabled:(BOOL)debugLogEnabled
34-
{
32+
- (void)setFd_debugLogEnabled:(BOOL)debugLogEnabled {
3533
objc_setAssociatedObject(self, @selector(fd_debugLogEnabled), @(debugLogEnabled), OBJC_ASSOCIATION_RETAIN);
3634
}
3735

38-
- (void)fd_debugLog:(NSString *)message
39-
{
36+
- (void)fd_debugLog:(NSString *)message {
4037
if (!self.fd_debugLogEnabled) {
4138
return;
4239
}

Classes/UITableView+FDTemplateLayoutCellHeightCache.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222

2323
#import <UIKit/UIKit.h>
2424

25-
NS_ASSUME_NONNULL_BEGIN
26-
2725
@interface FDTemplateLayoutCellIndexPathHeightCache : NSObject
2826

2927
- (BOOL)existsHeightAtIndexPath:(NSIndexPath *)indexPath;
3028
- (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath;
3129
- (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath;
32-
- (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath;
30+
- (void)clearHeightAtIndexPath:(NSIndexPath *)indexPath;
3331
- (void)clearAllheightCaches;
3432
- (void)insertSection:(NSInteger)section;
3533
- (void)deleteSection:(NSInteger)section;
@@ -45,19 +43,18 @@ NS_ASSUME_NONNULL_BEGIN
4543

4644
@interface FDTemplateLayoutCellKeyHeightCache : NSObject
4745

48-
- (BOOL)existsHeightForKey:(id <NSCopying>)key;
49-
- (void)cacheHeight:(CGFloat)height byKey:(id <NSCopying>)key;
50-
- (CGFloat)heightForKey:(id <NSCopying>)key;
51-
- (void)invalidateHeightForKey:(id <NSCopying>)key;
46+
- (BOOL)existsHeightForKey:(id<NSCopying>)key;
47+
- (void)cacheHeight:(CGFloat)height byKey:(id<NSCopying>)key;
48+
- (CGFloat)heightForKey:(id<NSCopying>)key;
49+
- (void)clearHeightForKey:(id<NSCopying>)key;
5250
- (void)clearAllheightCaches;
5351

5452
@end
5553

54+
/// Do not use directly.
5655
@interface UITableView (FDTemplateLayoutCellHeightCache)
5756

5857
@property (nonatomic, strong, readonly) FDTemplateLayoutCellIndexPathHeightCache *fd_indexPathHeightCache;
5958
@property (nonatomic, strong, readonly) FDTemplateLayoutCellKeyHeightCache *fd_keyHeightCache;
6059

6160
@end
62-
63-
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)