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
6
votes
1 answer
How to test property existence and type based on NSString typed key?
In my quest to update a Core Data model within my iOS project, I'm querying a server for JSON objects that correspond - to some extent - with the managed entities of my model. The end result I'm striving for is a reliable update solution from JSON…

epologee
- 11,229
- 11
- 68
- 104
6
votes
2 answers
Get specific CodingKey for KeyPath
Consider the following object:
struct User: Codable {
let id: Int
let email: String
let name: String
}
Is it posible to get a specific CodingKey for a given KeyPath?
let key = \User.name.codingKey // would be equal to string: "name"

Wiingaard
- 4,150
- 4
- 35
- 67
6
votes
5 answers
Case-insensitive KVC in Cocoa?
I'd appreciate some feedback on a particular approach I'm thinking of using. The scenario is below.
I have an object (lets call it MObject) that has a number of properties, say, x and y coordinates, height and width. The properties are named…

EightyEight
- 3,430
- 4
- 36
- 67
6
votes
1 answer
How do I set Swift values by property name?
Objective-C has a setValue method which allows the developer to set a specific value to a field by it's name.
How can I do that in Swift without inheriting from NSObject and actually use the setValue method?

YogevSitton
- 10,068
- 11
- 62
- 95
6
votes
3 answers
Get all the keys for a class
Recently I work with the function func setValue(_ value: AnyObject?, forKey key: String) of the NSKeyValueCoding protocol to change the text color of a UIPickerDate in the following way:
class ColoredDatePicker: UIDatePicker {
var changed =…

Victor Sigler
- 23,243
- 14
- 88
- 105
6
votes
2 answers
Objective C -- is there a keypath that will cause an object to return itself?
Given an object foo of class Foo, I want to do the following:
NSString *key = @"some key";
id myObj = [foo valueForKey: key];
and have myObj equal to foo.
Is there a way to do this without defining a category on Foo?

William Jockusch
- 26,513
- 49
- 182
- 323
6
votes
1 answer
Implementing a KVO/Bindings-Compliant Bridge-Pattern in Cocoa
I'm trying to implement a simple object bridge in cocoa where the bridge object acts as a kvo/bindings-compliant drop in for some arbitrary other NSObject instance.
Here is my problem (more details in the code below):
A bridge object acts as a drop…

flitzwald
- 20,200
- 2
- 32
- 28
6
votes
3 answers
Objective-c KVC: Collection Accessor Patterns for To-Many Properties, how can I use this to enhance my code?
I was reading :Collection Accessor Patterns for To-Many Properties, but I'm not sure where can I or should I use this.
Can someone please point out some scenarios that I can use Collection Accessor Patterns for To-Many Properties to make my code…

CarmeloS
- 7,868
- 8
- 56
- 103
6
votes
3 answers
"Key-Value Coding" for Java
In Objective-C on Apple there is something called "Key-Value Coding" that allows you to traverse the object graph using strings similar to filesystem paths. There's an informal protocol (i.e. interface) that allows objects to return values based on…

spieden
- 1,239
- 1
- 10
- 23
6
votes
1 answer
Finding if a class is key-value-compliant for a given key
Is there a method to find out if a class is key-value-compliant for a given key?

cfischer
- 24,452
- 37
- 131
- 214
5
votes
1 answer
Objective-C undo manager questions
I'm reading a book on Objective-c and learning about the undo manager. The concept seems very simple but the provided example seems overly complex. Basically, I have a table view connected to an NSArrayController and I add or remove people to an…

JPC
- 8,096
- 22
- 77
- 110
5
votes
0 answers
Key-value setting custom values for a SCNProgram OpenGL shader
According to Apple’s documentation “To update a value once, use key-value coding: Call the setValue:forKey: method, providing the uniform name from shader source code as the key and an appropriate type of data as the value.” (taken from SCNProgram…

Gary Makin
- 3,109
- 1
- 19
- 27
5
votes
1 answer
this class is not key value coding-compliant for the key name. UISearchBar and DisplayController
I'm making an app that uses a UITableViewController and I'm trying to add a UISearchBarWithDisplayController. (I'm using this tutorial: http://www.appcoda.com/search-bar-tutorial-ios7/). I followed all the steps, but when I press a letter on the…

ZenthyxProgramming
- 6,283
- 3
- 16
- 15
4
votes
5 answers
Read file and get key=value without using java.util.Properties
I'm building a RMI game and the client would load a file that has some keys and values which are going to be used on several different objects. It is a save game file but I can't use java.util.Properties for this (it is under the specification). I…

Samuel Guimarães
- 574
- 3
- 6
- 18
4
votes
2 answers
KVO: Cannot remove an observer
In my interface I have an NSTextField who's value is bound to an NSArrayController's selection.selectedType.title. All of the NSArrayController's objects are custom objects each with two methods:
- (MYType *)selectedType;
- (void)setSelectedType:…

Jef
- 2,134
- 15
- 17