0

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];
agupta
  • 403
  • 1
  • 7
  • 17

1 Answers1

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

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I get regions information as a string which I parse and build regions using it .I need to stop monitoring for regions that are no longer valid and start monitoring for regions that are new. – agupta May 12 '13 at 18:06
  • So, given the region info, just enumerate the first set and see if an equivalent region is already there. – matt May 12 '13 at 18:08
  • Or just stop monitoring everything you're monitoring and start over, as I suggest in my edited answer. Keep things simple. – matt May 12 '13 at 18:26
  • Yes that can be done,but since there can be lot of regions I was trying to optimize this part of code. – agupta May 12 '13 at 18:34
  • Don't optimize prematurely! CLRegion is insanely lightweight, little more than a struct. There is nothing to optimize here. Save your optimization for when you've actually got a speed/memory issue. – matt May 12 '13 at 20:07