key-value-observing

Key-Value Observing an NSMutableSet

泪湿孤枕 提交于 2019-11-30 04:03:32
问题 In a plain class I have a NSMutableSet property. Whenever objects are added to or removed from the set, I want to perform some custom code. I know I could write a few addObjectToSet: -like methods to the class, but I was wondering if there's a more elegant solution with direct KVO on the set. As it turns out, NSSet will raise an exception when you try to add an observer to it. Not surprisingly, for there's probably no named keyPath to observe. The documentation is pretty clear about the

Objective C:Object Deallocated while key value observers were still registered with it

为君一笑 提交于 2019-11-30 03:23:28
I am hitting the below error after I added 2 additional fields to my core data model. CarPark_CarPark_ was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: <NSKeyValueObservationInfo 0x1b6510> ( <NSKeyValueObservance 0x19b210: Observer: 0x1a8cf0, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x1b7e00> ) I am a little lost on what to do

How to get notified of changes to models via an NSArrayController?

▼魔方 西西 提交于 2019-11-30 00:52:39
I have an NSView subclass which is bound to the arrangedObjects of an NSArrayController . When the array has an item inserted or removed the view is notified. How do I get it to be notified if a model stored in the array has an attribute changed? Do I need to add my view as an observer to every (relevant) attribute of every item added to the array? When an item is added to or removed from the array I am notified via observeValueForKeyPath:ofObject:change:context: in my NSView subclass. I am not notified of changes to the models stored in the array but I could, every time I am notified of an

Best practices for context parameter in addObserver (KVO)

末鹿安然 提交于 2019-11-29 19:32:48
I was wondering what you should set the Context pointer in KVO when you are observing a property. I'm just starting to use KVO and I haven't gleaned too much from the documentation. I see on this page: http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/ the author does this: [annView addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:GMAP_ANNOTATION_SELECTED]; And then in the callback, does this: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ NSString

observeValueForKeyPath not being called

Deadly 提交于 2019-11-29 16:41:27
问题 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 %@

Updates to NSDictionary attribute in CoreData not saving

我是研究僧i 提交于 2019-11-29 16:10:15
问题 I have created an Entity in CoreData that includes a Transformable attribute type implemented as an NSDictionary. The NSDictionary attribute only contains values of a custom class. The properties of the custom class are all of type NSString. The custom class complies with NSCoding implementing: -(void)encodeWithCoder:(NSCoder*)coder; -(id)initWithCoder:(NSCoder *)coder When saving the Entity for the first time all attributes including the Transformable (NSDictionary) type are properly saved

Core Data keyPathsForValuesAffectingValueForKey only calling relationships, not attributes

岁酱吖の 提交于 2019-11-29 15:01:37
问题 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.

Use KVO for NSTextFields that are bound together

十年热恋 提交于 2019-11-29 14:36:58
问题 I'm having trouble getting KVO working with text fields that are bound together in a Cocoa app. I have gotten this to work when setting strings in NSTextFields with buttons but it is not working with bindings. As always, any help from Stack Overflow would be greatly appreciated. Purpose of my code is to: bind several text fields together when a number is input in one field, have the other fields automatically update observe the changes in the text fields Here's my code for MainClass which is

Parameters from observeValueForKeyPath:ofObject:change:context:

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 12:16:48
问题 I was wondering what the parameters from this method would return. - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context; In the documentation it says keyPath The key path, relative to object, to the value that has changed. object The source object of the key path keyPath. change A dictionary that describes the changes that have been made to the value of the property at the key path keyPath relative to object. context The

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

家住魔仙堡 提交于 2019-11-29 11:43:05
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:(CLLocationCoordinate2D)newCoordinate { CLLocation* newLocation = [[CLLocation alloc] initWithCoordinate: