key-value-coding

NSTableColumn bound to a BOOL value

i have NSTableView bound to an NSArrayController. in my model i have a BOOL field. i'm trying to bind that value to the column. it displays correctly (1 where value is YES and 0 where value is NO), but it's readonly. =( when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. colum...

What do these errors in the XCode Debugger Mean?

I have 2 errors in XCode and am trying to figure out what they mean. The 1st one: 2009-06-30 18:56:27.998 Spark[4584:10b] Error setting value for key path filterPredicate of object <NSArrayController: 0x1482c0>[entity: group, number of selected objects: 1] (from bound object <NSSearchField: 0x143f20> with object ID 1387 in Nib named...

Objective-C dot syntax tricks for when Key-Value won't work?

I'm iterating through some objects and trying to set some properties that, apparently, don't like Key-Value coding. so I'm unable to create a string at runtime to represent the "key". This line of ViewController won't compile: [self setValue:offsetX forKeyPath:[NSString stringWithFormat:@"myView%d.center.x", anInt]]; but I can set ...

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

How do you wrap up a BOOL for KVC in Cocoa/Obj-C?

I'm using KVC to iterating through a few views. Having trouble setting BOOL properties: [self setValue:YES forKeyPath:[NSString stringWithFormat:@"myView%d.userInteractionEnabled", n]]; I get: warning: passing argument 1 of 'setValue:forKeyPath:' makes pointer from integer without a cast. There is no [NSValue valueWithBool:YES] or si...

Why do these errors in Xcode Mean?

2009-07-06 06:49:13.666 Spark[9825:10b] -[<NSUserDefaultsController 0x137af0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hotKeyDisplayEntry. 2009-07-06 06:49:13.667 Spark[9825:10b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSUserDefaultsController 0x137...

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 KVC question: "class is not key value coding-compliant"

I'm trying to update some properties with KVC. The properties have been synthesized. This line works: myObject.value = intValue; This doesn't work: [self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"]; And blows up with: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:f...

In which situations would an object not be key-value coding compliant?

Currently I'm learning all the stuff around key-value coding. In the docs they say: Any object in the key path sequence that is not key-value coding compliant for the appropriate key receives a valueForUndefinedKey: message. I try to imagine a situation where an object is not key-value coding compliant. How could that happe...

Why should I use KVC rather than the simple dot syntax when accessing object properties?

There's the option to go the long way, if an receiver class conforms to the NSKeyValueProtocol: [myInstance setValue:[NSNumber numberWithInt:2] forKey:@"integerProperty"]; or the short way: myInstance.integerProperty = 2; what's the point of this KVC method? When is this useful? ...

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

Using key paths in NSPredicates

I have an NSDictionary which contains (my custom) GTPerson objects. GTPerson has an NSMutableSet *parents attribute, on which I use @property and @synthesize. Out of my NSDictionary, I want to filter all the GTPerson objects which don't have any parents, i.e. where the count of parents is 0. I'm using the following code: NSPredicate ...

Accessing constants using Key-Value Coding in Objective-C

I'm making a program that has a lot of constants. I decided to put them all into a separate class and I'm importing it by the classes that need it. The files look similar to this // Constants.h extern const int baseCostForBuilding; extern const int maxCostForBuilding; // etc // Constants.m const int baseCostForBuilding = 400; const int...

Cocoa bindings and KVC with CGColorRef

I'm trying to bind a CGColorRef on one of my objects to the "shadowColor" property of a CALayer. Unfortunately, I haven't been able to figure this out - it's probably something really simple! The CGColorRef is implemented as a property: @property (readwrite) CGColorRef labelShadowColor; My binding is straight forward too: [aLayer bi...

How to Key-Value-Observe the rotation of a CALayer?

I can access the value like this: NSNumber* rotationZ = [myLayer valueForKeyPath:@"transform.rotation.z"]; But for some reason, if I try to KV-observe that key path, I get a compiler error. First, this is how I try to do it: [myLayer addObserver:self forKeyPath:@"transform.rotation.z" options:0 context:nil]; The compiler tells me: ...

KVO rocks. Now how do I use it asynchronously?

I am sold on KVO but if used in the obvious way it is synchronous. I would like to use it in a situation where I am firing off many KVO messages in rapid succession and it is causing my app to grind to a halt as the KVO messages are handled. Can someone suggest an approach - perhaps using NSOperation or NSThread - that will work here. M...

key-value-coding a UIView's ivars

I'm interested in running some methods when my UIView is changed, either through a frame change or an affine transformation. My best idea is to do this by observing value changes for: myView.frame and myView.transform. However, the view portion of UIViews is not Key-Value complaint. Fortunatly the model portion of the view, the CAL...

KVC/KVO and bindings: why am I only receiving one change notification?

I'm seeing some quirky behaviour with Cocoa's KVC/KVO and bindings. I have an NSArrayController object, with its 'content' bound to an NSMutableArray, and I have a controller registered as an observer of the arrangedObjects property on the NSArrayController. With this setup, I expect to receive a KVO notification every time the array is ...

Observing NSTreeController's bound CoreData entities for insertion/removal

I am creating my own bindable custom treeview. For that I would like to observe NSTreeController for updates to its items' to-many-relationships. NSTreeController is bound to CD managed object context. Every depth level has its own CD Entity with parent/children/isLeaf properties. I need to maintain same hierarcy in the view (and order o...

Out of scope in KVC generated array

I'm trying to create an array of objects from a hierarchy of other objects like this: code 1: childController.names = [[NSMutableArray alloc] init]; for (Person *p in list.persons) { [childController.names addObject:p.name]; } code 2: NSMutableArray *testArray = [list.persons valueForKey:@"name"]; The first code snippet works...