Key Value Coding is a mechanism for accessing an object’s properties indirectly, using strings to identify properties, rather than through invocation of an accessor method or accessing them directly through instance variables.
Questions tagged [key-value-coding]
390 questions
13
votes
1 answer
Interface Builder's User Defined Runtime Attributes not accepting floats?
I created an NSView subclass that has a float property and I'd like to set it in Interface Builder. In the User Defined Runtime Attributes section the only suitable Type is Number. But if I want to enter a decimal number (either using . or , as…

DrummerB
- 39,814
- 12
- 105
- 142
12
votes
1 answer
KVC in UITableView subclass causing crash with accessibility enabled
I have a custom UITableView subclass in which I override +accessInstanceVariablesDirectly to return NO in order to ensure attributes with no setter cannot be set using KVC.
When removing this table view from the view hierarchy, the app crashes -…

Christian Schnorr
- 10,768
- 8
- 48
- 83
12
votes
4 answers
Cocoa Key Value Bindings: What are the explanations of the various options for Controller Key?
When I bind a control to an NSArrayController using Interface Builder, there are a variety of options under the "Controller Key" field in the bindings inspector.
I understand what "arrangedObjects" is, and I semi-understand what "selection" is, but…

Elisabeth
- 2,972
- 6
- 35
- 39
11
votes
3 answers
How to convert NSValue to NSData and back?
A have a number of NSValue (obtained via KVC valueForKey) that I need to append to an NSData object in order to send it over the network using Game Center. Obviously I will also need to convert the NSValue back from NSData for more KVC…

CodeSmile
- 64,284
- 20
- 132
- 217
11
votes
2 answers
Observing the editing property of a UITableViewController
Why can't I observe the editing property of an instance of UITableViewController?
I'm using the following code:
[self addObserver:self
forKeyPath:@"editing"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
…

Senseful
- 86,719
- 67
- 308
- 465
11
votes
2 answers
Keypath for first element in embedded NSArray
This example is contrived, but it shows my point.
So, if I have an object graph like the following:
{
sex = male;
uid = 637650940;
work = ({
employer = {
id = 116420715044499;
name = "Software Engineer";
};
"end_date" =…

Paul de Lange
- 10,613
- 10
- 41
- 56
10
votes
1 answer
Key-value observing on UIButton's State
UIButton has a state property, which appears to be KVO compliant by all accounts and there is no documentation to indicate otherwise. However, when I added an observer to a UIButton's state property, the observer callback was never invoked. How…

Evil Nodoer
- 1,927
- 3
- 23
- 32
10
votes
2 answers
Why does valueForKey: on a UITextField throws an exception for UITextInputTraits properties?
Running this:
@try
{
NSLog(@"1. autocapitalizationType = %d", [self.textField autocapitalizationType]);
NSLog(@"2. autocapitalizationType = %@", [self.textField valueForKey:@"autocapitalizationType"]);
}
@catch (NSException *exception)
{
…

0xced
- 25,219
- 10
- 103
- 255
10
votes
2 answers
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…
Chris
10
votes
2 answers
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:'…

Meltemi
- 37,979
- 50
- 195
- 293
9
votes
1 answer
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…

David Liu
- 9,426
- 5
- 40
- 63
9
votes
2 answers
Objective C keypath to get all artists from iTunes
I'm using key-value-coding to get all the artists from iTunes:
[self.iTunes valueForKeyPath:@"sources.@distinctUnionOfArrays.playlists.@distinctUnionOfArrays.tracks.artist"];
Now, this works fine.
This is very efficient. I would also like to do…

IluTov
- 6,807
- 6
- 41
- 103
9
votes
2 answers
How to get the largest value from NSArray containing dictionaries?
How do you get the largest value from an NSArray with dictionaries?
Lets say I have NSArray containing dictionaries with keys "age", "name", etc.
Now I want to get the record with the highest age.
Is this possible with some KVC magic? Or do I have…

cmd
- 129
- 1
- 5
8
votes
2 answers
What's the difference between KVC and Properties?
So, I've already read up on the documentation which notes
Objective-C 2.0’s dot syntax and key-value coding are orthogonal technologies. You can use key-value coding whether or not you use the dot syntax, and you can use the dot syntax whether or…

Vervious
- 5,559
- 3
- 38
- 57
8
votes
2 answers
Using setValuesForKeysWithDictionary with child objects and JSON
I have a json string
{"name":"test","bar":{"name":"testBar"}}
In objective c I have an object
@interface Foo : NSObject {
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Bar * bar;
@end
And I just synthesize those…

Tavis Bones
- 255
- 4
- 12