key-value-observing

Observing model changes with Cocoa Bindings and NSArrayController

I've got an NSArrayController bound to a mutable array in my controller, which manages an array of my model objects. The array controller is bound to my UI. It works well. Now I'm trying to manually observe when a value changes in my model in my controller class (basically I'm marking the changed model as "needsToSave" for later on, but...

Updates to NSDictionary attribute in CoreData not saving

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;...

iPhone OS: KVO: Why is my Observer only getting notified at applicationDidfinishLaunching

I am basically trying to implement an achievement tracking setup in my app. I have a managedObjectModel class called StatTracker to keep track of all sorts of stats and I want my Achievement tracking class to be notified when those stats change so I can check them against a value and see if the user has earned an achievement. I've tr...

using KVO to update an NSTableView filtered by an NSPredicate

My UI is not updating when I expect it to. The application displays "projects" using a view similar to iTunes -- a source list on the left lets you filter a list (NSTableView) on the right. My filters update properly when they are examining any simple field (like name, a string), but not for arrays (like tags). I'm removing a tag f...

Setting up a "to-many" relationship value dependency for a transient Core Data attribute

I've got a relatively complicated Core Data relationship structure and I'm trying to figure out how to set up value dependencies (or observations) across various to-many relationships. Let me start out with some basic info. I've got a classroom with students, assignments, and grades (students X assignments). For simplicity's sake, we ...

how to udate window controls(NSTextField,NSCheckbox and etc) in binding manually

Hi, I am working on an application in which i need to store all the NSObject subclass properties into plist file and then allow users to store it and restore it. We call it profile and it can restore the saved state of all the controls/views on the window in my application. I have completed the storing/Restoring part, but the issue is ...

iPhone OS: Is there a way to set up KVO between two ManagedObject Entities?

I have 2 entities I want to link with KVO, one a single statTracker class that keeps track of different stats and the other an achievement class that contains information about achievements. Ideally what I want to be able to do is set up KVO by having an instance of the achievement class observe a value on the statTracker class and also ...

How can I write cocoa bindings as code instead of in the Interface Builder?

In my modell got an NSMutableArray that keeps track of a changing number of elements. In my view I got a NSTextField that shows the number of elements. The view gots unarchived from the nib file and alloc/inits the modell. Therefore it knowns about the modell and the contained array. I established the connection as follows. In the Inter...

If I wanted to write my own KVO-compliant setter method, would it look something like this?

- (void)setFirstName:(NSString*)firstNameValue { [self willChangeValueForKey:@"firstName"]; [firstName release]; firstName = firstNameValue; [firstName retain]; [self didChangeValueForKey:@"firstName"]; } Is that right? So the willChange... foobar didChange... block causes an KVO notification to fire? ...

Do you know of any Key-Value-Coding and Key-Value-Observing session videos on the net?

I know Apple is not the only ressource out there, and many people create great videos in conferences and presentations. If someone knows a great video or podcast on the topics KVC or KVO, please let me know. I would be glad about it! Edit: Changed Title so it's more clear this is indeed programming related. KVO / KVC / MVC != KFC ...

Difference between mutableArrayValueForKey and calling insertObject:inEmployeesAtIndex: directly

I have a question regarding using KVO-compliant methods to insert/remove objects from an array. I'm working through Aaron Hillegass' Cocoa Programming for Mac OS X and I saw the following line of code (in the insertObject:inEmployeesAtIndex: method: [[undoManager prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];...

Subclassing/extending NSMutabelSet?

Hey, Is it possible to to subclass NSMutableSet? I need to do this in order to not retain objects contained in this set. The purpose todo that is to make an set of observers and those do not need to be retained. Is it possible to do this or maybe you have an another solution. Needles to say, I do know KVO but the pattern I have descri...

Using KVO with custom UITableViewCell and CoreData

I've read over a ton of documentation and tutorials about KVO but I haven't found any that I've been able to abstract for my application. I have a table view that uses a custom UITableViewCell class to provide an interface for turning options on/off. The cell has a UISwitch that I would like to "bind" to my model's boolean properties. ...

How do I ensure proper KVO behaviour for my NSSlider-like custom control?

Hi, Let's say you have a custom control similar to NSSlider but with support for choosing a range of values, instead of a single value. The obvious choice of properties is minValue, maxValue, leftValue, rightValue, or however you wanna name them. You'd probably also want to make sure that leftValue and rightValue always lay in between m...

Core Data, KVO, and NSInternalInconsistencyException

I'm using Core Data and KVO to look for changes in values to trigger saves to the data store. I have a table view with search hooked up to NSFetchedResultsController. When the search changes, a new results controller is made on pressing the Search button. When the user selects an item in the results table view, then the user enters a det...

Key Value Observing and NSButton state

I'm trying to observe checkbox status and make appropriate changes in the app when checkbox status changes. In a window manager that manages the window with checkbox I have following observer setup: - (void)awakeFromNib { [myCheckBox addObserver:self forKeyPath:@"state" options:(NSKeyValueObser...

Registering a bool for a NSNotification.

Hi everyone, I'm trying to wrap my head around NSNotification but can't seem to get it to work. Think I'm misunderstanding how to register for an notification. I have a bool as a property in my connection manager class. At initialisation I authenticate with a few servers and check if I can access an external URL (App will mainly be use...

Do you need to call willChangeValueForKey: and didChangeValueForKey: ?

I thought home-cooked @property setters were supposed to look like this: -(void) setFoo:(Foo *)newFoo { // Safeguards // ... [self willChangeValueForKey:@"foo"]; // Switcheroo // ... [self didChangeValueForKey:@"foo"]; } But I see a lot of code in blog posts by people who've been doing Cocoa a lot longer than I have, wh...

KVO problem "Cannot remove an observer"

I have an NSArrayController linked to a Core Data object, set to Auto Rearrange Content and filtered by a predicate. All is well until I try to nullify a relationship and assign another. At that point, my application crashes and I receive the following error: Cannot remove an observer for the key path "career.type" from Object...

Performance speed of KVO and NSNotifications?

Should I be afraid of using Key-Value Observations (KVO) and NSNotifications? I'm beginning to use them in my app, but I'm a little unfamiliar with the concept of something that could possibly be triggering an appwide call or automatically doing stuff, and a little afraid of the performance hit that such overhead could bring. Are my con...