Commit a9b29a01 authored by 汪洋's avatar 汪洋

添加可以不去重的方法

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