key-value-observing

Understanding KVO in iOS

本小妞迷上赌 提交于 2019-11-30 13:18:35
问题 Regarding "Ensuring KVO Compliance", there are some official definition which seem like hard to understand In order to be considered KVO-compliant for a specific property, a class must ensure the following; The class must be key-value coding compliant for the property as specified in Ensuring KVC Compliance. The class must allow automatic observer notifications for the property, or implement manual key-value observing for the property. Who can give more specific examples to make this more

observeValueForKeyPath not being called

时光毁灭记忆、已成空白 提交于 2019-11-30 11:12:37
I have a ViewController creating an instance of a UIView, and then I register an observer with the instance, such that logoAnimation = [[MainLogoAnimation alloc] init]; [logoAnimation addObserver:self forKeyPath:@"patrocinioDidLoad" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil]; then, in the same file, I have: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"%@ \n %@ \n %@ \n ",keyPath,object,change); } But, although I have checked and double-checked that logoAnimation

Organizing memcache keys

こ雲淡風輕ζ 提交于 2019-11-30 10:50:48
Im trying to find a good way to handle memcache keys for storing, retrieving and updating data to/from the cache layer in a more civilized way. Found this pattern, which looks great, but how do I turn it into a functional part of a PHP application? The Identity Map pattern: http://martinfowler.com/eaaCatalog/identityMap.html Thanks! Update: I have been told about the modified memcache (memcache-tag) that apparently does do a lot of this, but I can't install linux software on my windows development box... Well, memcache use IS an identity map pattern. You check your cache, then you hit your

Core Data keyPathsForValuesAffectingValueForKey only calling relationships, not attributes

谁说胖子不能爱 提交于 2019-11-30 10:15:14
I am using Core Data to model an entity which has both attributes and relationships. I would like to make one of the attributes dependent on two other relationships. The Core Data FAQ and several other examples use +(NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key for this purpose. However, this only seems to be called for all of my relationship properties, but not for any of the attributes. In addition keyPathsForValuesAffecting<key> never gets called for any of my attributes. Is this the normal behaviour or am I missing something? How can I calculate one attribute based on

iOS MapKit dragged annotations (MKAnnotationView) no longer pan with map

梦想的初衷 提交于 2019-11-30 09:04:53
问题 I'm learning to use MapKit in my fledgling iOS app. I'm using some of my model entities as annotations (added the <MKAnnotation> protocol to their header file). I also create custom MKAnnotationViews and set the draggable property to YES . My model object has a location property, which is a CLLocation* . To conform to the <MKAnnotation> protocol, I added the following to that object: - (CLLocationCoordinate2D) coordinate { return self.location.coordinate; } - (void) setCoordinate:

How to observe individual array element changes (update) with Swift and KVO?

妖精的绣舞 提交于 2019-11-30 07:32:27
Do I need to subscribe/unsubscribe to individual elements of an array? I want to update each table view cell individually to reflect changes in the backing array. By changes I mean not append/remove operations but update of the properties of the objects of the array. I hope I was able to explain what I want to achieve. Thanks To use KVO, declare the model object with dynamic properties: class Foo: NSObject { @objc dynamic var bar: String // in Swift 3, `@objc` is not necessary; in Swift 4 we must make this explicit init(bar: String) { self.bar = bar super.init() } } Then, let the cell process

Understanding KVO in iOS

僤鯓⒐⒋嵵緔 提交于 2019-11-30 06:58:59
Regarding "Ensuring KVO Compliance", there are some official definition which seem like hard to understand In order to be considered KVO-compliant for a specific property, a class must ensure the following; The class must be key-value coding compliant for the property as specified in Ensuring KVC Compliance. The class must allow automatic observer notifications for the property, or implement manual key-value observing for the property. Who can give more specific examples to make this more clear ? Thanks Benedict Cohen Take a look at Ensuring KVO Compliance the Automatic Versus Manual Support

Observing Changes to a mutable array using KVO vs. NSNotificationCenter

不打扰是莪最后的温柔 提交于 2019-11-30 06:26:24
问题 In my model I have an array of objects called events. I would like my controller to be notified whenever a new object is added to events. I thought that a good way to do this would be use the KVO pattern to get notified when the events changes (from a new object being added) // AppDelegate // events is a NSMutableArray @property/@synthesize etc... [appDelagate addObserver:self forKeyPath:@"events" options:NSKeyValueObservingOptionNew context:NULL]; But the observeValueForKeyPath method wasn't

When should I remove observers? Error about deallocating objects before removing observers

时光毁灭记忆、已成空白 提交于 2019-11-30 06:19:16
问题 I am trying to use key-value observing in one of my classes. I register the observers in the init method and remove/deregister them in the dealloc, but I get the following error which seems to occur before my dealloc method gets called, according to my debug prints. An instance 0x583870 of class TekkPoint is being deallocated while key value observers are still registered with it. Observation info is being leaked, and may even become mistakenly attached to some other object. Set a breakpoint

In Cocoa KVO, why doesn't a change on a NSMutableArray proxy notify observers?

旧巷老猫 提交于 2019-11-30 04:46:43
问题 I'm implementing a DocumentsManager class in iOS, and I want to make a to-many property called documents to be KVO compliant. It seems to mostly work, and my KVO accessor and mutator methods are called. The thing that bothers me, however, is that any change made directly on the NSMutableArray proxy returned by calling mutableArrayValueForKey: on my instance doesn't notify observers. So, this code notifies me about the insertion of @"aaa" but not of @"bbb" , although they are both actually