Commit a9b29a01 authored by 汪洋's avatar 汪洋

添加可以不去重的方法

parent 7011e4f2
......@@ -81,6 +81,10 @@
*/
NSString *_deduplicationKey;
}
@property (nonatomic, copy) NSArray *notDeduplicate;
// 去重时被去掉的数据总计。在上拉加载更多时,这个数目仍要被用上,否则在某种极端的情况下,startNum会与服务器对不上,导致出现没有数据返回
@property (nonatomic,assign) NSInteger deleteCount;
/** @brief 记录服务器返回的字段 message 用来显示空白文案*/
@property (nonatomic, strong) NSString *message;
......
......@@ -10,8 +10,7 @@
@implementation WMFetchDataViewModel
{
// 去重时被去掉的数据总计。在上拉加载更多时,这个数目仍要被用上,否则在某种极端的情况下,startNum会与服务器对不上,导致出现没有数据返回
NSInteger _deleteCount;
}
- (instancetype)init{
self = [super init];
......@@ -162,6 +161,10 @@
// NSMutableArray 不是线程安全的,不能使用并行枚举。参考https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([self.notDeduplicate containsObject:obj[@"type"]]) {
id object = buildBlock(obj);
[result addObject:object];
} else {
id value = [obj valueForKey:_deduplicationKey];
NSString *key = [value isKindOfClass:[NSString class]] ? value : [value stringValue];
NSAssert(key.length > 0, @"key 怎么会是一个空???!!!");
......@@ -174,7 +177,8 @@
}
_deduplicationDic[key] = @1;
}else{
_deleteCount ++;
self.deleteCount ++;
}
}
}];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment