美文网首页
NSMutableSet的使用

NSMutableSet的使用

作者: 菠罗吹雪 | 来源:发表于2017-06-05 10:48 被阅读0次

NSMutableSet的使用

- (void)updateMapViewAnnotationsWithAnnotations:(NSArray *)annotations

{

/* 用户滑动时,保留仍然可用的标注,去除屏幕外标注,添加新增区域的标注 */

NSMutableSet *before = [NSMutableSet setWithArray:self.mapView.annotations];

[before removeObject:[self.mapView userLocation]];

NSSet *after = [NSSet setWithArray:annotations];

//之前是123

//之后是2345

//123,2345

/* 保留仍然位于屏幕内的annotation. */

NSMutableSet *toKeep = [NSMutableSet setWithSet:before];

[toKeep intersectSet:after];//留下相同的。//23留下

/* 需要添加的annotation. */

NSMutableSet *toAdd = [NSMutableSet setWithSet:after];

[toAdd minusSet:toKeep];////向集合中删除另一个集合出现的元素//删除相同的,除 了23的,45要添加

/* 删除位于屏幕外的annotation. */

NSMutableSet *toRemove = [NSMutableSet setWithSet:before];

[toRemove minusSet:after];//向集合中删除另一个集合出现的元素// 23相同,只有1不同,删除

/* 更新. */

dispatch_async(dispatch_get_main_queue(), ^{

[self.mapView addAnnotations:[toAdd allObjects]];

[self.mapView removeAnnotations:[toRemove allObjects]];

});

}

相关文章

  • NSMutableSet的使用

    NSMutableSet的使用 - (void)updateMapViewAnnotationsWithAnnot...

  • ios杂谈

    NSMutableSet *set=[NSMutableSet new]; NSMutableArray *arr...

  • 对数组合并同类项

    去除同类项使用NSMutableSet集合特性,及NSPredicate谓词过滤器,实现去重,分类,比较方便,有用...

  • 重用机制原理

    重用池:2个NSMutableSet的队列,一个等待使用队列,一个使用中的队列。 自定义的重用池使用方法: 自定义...

  • NSHashTable:NSMutableSet 的替代品?

    NSHashTable 解决了什么问题 使用 NSMutableSet 时,主要有两个让开发者如鲠在喉的地方: 加...

  • Thread-safe Container

    系统的NSMutableArray,NSMutableDictionary,NSMutableSet都是线程不安全...

  • iOS NSHashTable、NSMapTable、NSPoi

    NSHashTable 类似NSSet 、 NSMutableSet,与其区别在于NSSet 、 NSMutabl...

  • NSSet和NSMutableSet

    集合是无序的而不随机的,而且不会存在两个相同的元素,如果在设置的时候放入了两个相同的元素,系统会自动删掉一个元素;...

  • NSHashTable

    NSHashTable 是更广泛意义的NSSet,区别于NSSet / NSMutableSet,NSHashTa...

  • iOS中的NSHashTable和NSMapTable

    首先说NSHashTable: NSHashTable效仿了NSSet(NSMutableSet),但提供了比NS...

网友评论

      本文标题:NSMutableSet的使用

      本文链接:https://www.haomeiwen.com/subject/hqrifxtx.html