key-value-observing

How to add an object to a programatically bound NSMutableArray?

I have an NSDocument which has the following structure: @interface MyDocument : NSDocument { NSMutableArray *myArray; IBOutlet NSArrayController *myArrayController; IBOutlet MyView *myView; } @end I instantiate the NSArrayController and the MyView in MyDocument.xib, and have made the connections to the File's Owner (MyDoc...

How to detect a property return type in Objective-C

Hello, I have an object in objective-c at runtime, from which I only know the KVC key and I need to detect the return value type (e.g. I need to know if its an NSArray or NSMutableArray) of this property, how can I do that? ...

KVO and Bindings problems using my own (not the shared) NSUserDefaults object

I'm subclassing NSUserDefaults in my application. A side effect of this is I can't use [NSUserDefaults sharedUserDefaults], I have to have a class method to provide my own static defaults object. This isn't been a problem in code, but it's proving tricky now that I'm hooking up the preferences UI with bindings. The shared NSUserDefaults...

How do I find all the property keys of a KVC compliant Objective-C object?

Hello, Is there a method that returns all the keys for an object conforming to the NSKeyValueCoding protocol? Something along the lines of [object getPropertyKeys] that would return an NSArray of NSString objects. It would work for any KVC-compliant object. Does such a method exist? I haven't found anything in searching the Apple docs ...

Disable automatic selection of a row after as NSTableView is populated

I have two NSTableViews populated with Core Data that are linked using bindings. When a row is selected in NSTableView1, NSTableView2 is populated and the first row in it is selected. I have registered the NSArrayController that corresponds to NSTableView2 with KVO on its selectionIndex. This is so that when a row is selected in NSTab...

Key Value Observing in Cocoa, introspecting the change property

Hey all, I'm using key value observing on a boolean property an NSObject method: -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context The most interesting part of the value for this key path is a B...

How to typecast an id to a concrete class dynamically at runtime?

Hi everyone, I have several dataSources I use for one UIViewController. My view controller uses KeyValue Observing in order to follow the state of certain properties at runtime. When I swap dataSources, I need to stop observing those properties. The problem is, I'm not sure of the class of the dataSource at runtime, therefor something l...

Should "to-many" relationships be modelled as properties?

After reading the Key-Value Coding Programming Guide, the Key-Value Observing Programming Guide and the Model Object Implementation Guide, as well as reading many StackOverflow entries on the topic and experimenting with various modelling scenarios, I feel like I have a good grasp on how to model my data. I end up using declared propert...

Index of the change in an NSArrayController

I'm programmatically observing the arrangedObjects of an NSArrayController and am having problem getting the index where something was changed. Is it at all possible to get the Index/IndexSet where the change occured. It seems like it should be, since NSKeyValueChangeIndexesKey is defined for the change-dictionary. When inspecting the ...

Cocoa bindings: custom setter methods?

I'm using Cocoa bindings to manage a table of objects. I understand how bindings work but I've run into a slight problem. Managing the table of objects would be fine and dandy, except that those objects have to manage actual bluetooth hardware. I'm working off of a framework that provides a class representing a connection to this hardwar...

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

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

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

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

KVO on the iPhone on 3.0 vs 2.2.1, having an issue

Appears the 3.0 NDA has been lifted, so this should be safe to ask. If this is violating an NDA, please let me know so I can remove the post, post-haste. I have a very trivial implementation for KVO on an NSOperationQueue. My problem is that when compiling against 2.2.1 SDK, I get different results for the NSOperationQueue in question f...

Objective-C: What's the Difference between objectForKey and valueForKey?

What is the difference between objectForKey and valueForKey? I looked both up in the documentation and they seemed the same to me. ...

Cocoa Touch Question. Using KVO in a touch sequence context

I would like to use KVO in the following context: 1) In touchesBegan:withEvent: I alloc/init an instance of an object that I then observe via KVO My intent is to observe varous behaviors of the object throughout its life time. 2) In touchesEnded:withEvent: I assign this instance to an NSMutableArray and release the instance reference ...

How do I observe the creation/destruction of an object instance?

I am smitten by KVC/KVO. Super powerful. There is one problem though. I'm trying to be true the the MVC etho but I see no way to use an observation pattern to monitor the allocation or deallocation of an Objective-C class instance. This is actually important as I have a model with fine-grained internal messaging that I want to observe f...

Performance hit incurred using NSMutableDictionary vs. NSMutableArray>

I am considering using an NSMutableDictionary in place of my current NSMutableArray. This is primarily for KVC/KVO reasons. The collection will undergo heavy mutation within the inner loop of my drawing method. Can I expect to incur a significant performance hit if I go ahead with this replacement? Cheers, Doug ...

Cocoa Touch Programming. KVO/KVC in the inner loop is super slow. How do I speed things up?

Hello, I've become a huge fan of KVO/KVC. I love the way it keeps my MVC architecture clean. However I am not in love with the huge performance hit I incur when I use KVO within the inner rendering loop of the 3D rendering app I'm designing where messages will fire at 60 times per second for each object under observation - potentially h...

How do I tell a (managed) object to notify its KVOs that one of its properties needs to be recached?

When we have an object who has a property that's generated based on other properties, usually we implement the +keyPathsForValuesAffecting{PropertyName} class method. What I'm trying to do is basically the same thing for a property on my NSManagedObject, but traversing a relationship. My model is simple; I have two Entities, App and Ve...

NSDictionary setValue:

OK, this is driving me nuts -- please tell me I'm not losing my mind! I declare: NSMutableDictionary* generalSettingsDict; im my .h I init: generalSettingsDict = [[NSMutableDictionary alloc] initWithCapacity:5]; in a viewWillAppear I set: [generalSettingsDict setValue:[NSNumber numberWithBool:control.on] ...