简体   繁体   English

NSSet与CLRegion对象

[英]NSSet with CLRegion Objects

I have two sets one obtained using 我有两组使用

NSMutableSet *monitoredRegionSet = [[locationManager monitoredRegions]mutableCopy];

and the other is obtained using the 另一个是使用

NSMutableSet *regionSet = [NSMutableSet setWithCapacity:regionChunks.count];
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:radius        
identifier:regionString];
[regionSet addObject:region];

When I try to set operations between them it does not works.Should I implement a category of CLRegion and implement the isEqual: and hash: methods.Is there a better approach of doing this. 当我尝试在它们之间设置操作时不起作用,应该实现CLRegion的类别并实现isEqual:和hash:方法,有没有更好的方法

[monitoredRegionSet intersectSet:regionSet];
[monitoredRegionSet minusSet:regionSet];
CLRegion *region = 
    [[CLRegion alloc] initCircularRegionWithCenter:coordinate 
        radius:radius        
    identifier:regionString];

That is a totally new, different region object. 那是一个全新的,不同区域的对象。 In the absence of any built-in concept of region equality, you are guaranteed that there is no intersection between a set containing this region object and a previously existing set of region objects. 在没有任何内置的区域相等概念的情况下,可以确保在包含此区域对象的集合与先前存在的区域对象的集合之间不存在交集。

As you rightly imply, you could play with CLRegion isEqual: and hash . 正确地暗示,您可以使用CLRegion isEqual:hash But is that something you really want to do? 但这是您真正想要做的吗? A better question might be: what are you actually trying to accomplish here? 一个更好的问题可能是:您实际上想在这里完成什么? For example, it might be more appropriate and simpler just to draw the regions for the second set directly from the first set. 例如,仅从第一组直接绘制第二组的区域可能更合适,更简单。

EDIT: Your simplest approach might be something like this: 编辑:您最简单的方法可能是这样的:

https://stackoverflow.com/a/7197192/341994 https://stackoverflow.com/a/7197192/341994

Just stop monitoring all the regions and start over with a new set of regions (some of which, of course, might happen to be the same as a region you were already monitoring). 只需停止监视所有区域,然后从一组新的区域开始(当然,其中一些区域可能恰好与您正在监视的区域相同)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM