This week I tried to subclass CLRegion
class by adding new properties and methods on it and then monitor it.
@interface MyClass : CLRegion
I did this because I found it way cleaner than storing separately the CLRegion
, and the added properties separately.
I implemented the NSSecureCoding
and NSCopying
protocol in this subclass to make it work.
Everything went fine for monitoring this subclass with startMonitoringForRegion:
or stopMonitoringForRegion:
.
But when retrieving existing regions with (NSArray *)monitoredRegions:
my problem occurs:
If I identify the region as a subclassed Region by the identifier,
and then cast it to the subclassed class (MyClass *) to call specific methods,
this doesn't work and I get a "unknown selector for CLCircularRegion" exception.
I highly suspect that this doesn't work because there is no such thing as virtual methods in Objective-C and so the son's init//initWithCoder//encodeWithCoder//.. is not called when the objects are builded by monitoredRegions.
As for know, i'm forced to store the additionals properties in NSUserDefaults
and retrieve it when I identify the region, but I find it a little bit dirty...
So is there a way to do it like this ? Or should I keep the NSUserDefault
solution ?