I have class A, with instance variables deriving attributes from cached data, this cached data is represented as a singleton and is part of A (it's essentially a NSDictionary). From time to time, this cache is modified.
When this happens, I would like to have all A instances pull new information from the cache the next time they access their attribute , or in other words, invalidate their attribute content.
Up to now, each instances is notified manually (using a static array to track members). I'm not a fan. There's might be an option with notification centre, but I'd rather try with KVO.
Has anyone ever managed to subscribe to KVO changes from a class variable on iOS ? (in other words, use changes from a static variable of A to tell A-instances to refresh their data.)
in otherwords, I'd love to have
static void* context = &context;
static myHadHocObject* msignal;
and later in Class A code
[msignal addObserver:self forKeyPath:@"operation" options:NSKeyValueObservingOptionNew context:context];
and be notified of msignal changes in a class instance via
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
}
I've tried to use various had hoc classes, with no luck. Seems I'm missing something.
pointers are welcome, thanks !
Aucun commentaire:
Enregistrer un commentaire