简体   繁体   中英

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.

[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 . 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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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