Questions tagged [key-value-coding]

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.

390 questions
8
votes
3 answers

Key-Value-Observing a to-many relationship in Cocoa

I am trying to get key-value-observing to work for an NSMutableArray. Below is the .h file for MyObservee, the observed class: @interface MyObservee : NSObject { @private int someValue; @private NSMutableArray *someArray; } @property…
Sam Lee
  • 7,049
  • 10
  • 42
  • 47
8
votes
1 answer

How do I attatch a Key value pair to a UIView on iPhone?

When I started iPhone development, I read somewhere that it's possible to attach a key value pair to a UIView. I understood that all UIViews could be used as dictionaries to store any data you may want to attatch to them to prevent unnecessary…
Nick Cartwright
  • 8,334
  • 15
  • 45
  • 56
7
votes
1 answer

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,…
Pascal Bourque
  • 5,101
  • 2
  • 28
  • 45
7
votes
1 answer

KVO differentiating between willChangeValueForKey and didChangeValueForKey - are both necessary?

In line with Apple's own recommendations, when setting KVC/KVO compliant accessors manually, one should include BOTH KVO methods willChange and didChange. This is what I have done in all my manual accessor methods. However,…
VectorVictor
  • 693
  • 1
  • 10
  • 20
7
votes
4 answers

What does "Controller Key" mean in Interface Builder > Inspector > Bindings?

I can't find in the Docs where they explain all those fields and what they mean. Especially "Controller Key" is not clear to me.
7
votes
1 answer

iPhone key-value coding -- test for existence of key

Does iPhone key-value-coding have a way to test whether a class will accept a given key? That is, without implementing the valueForUndefinedKey: or setValue: forUndefinedKey: method of the target class, I want to be able to do something like…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
7
votes
1 answer

Why can I not use KVC from an Objective-C object to a Swift Property?

My team has decided that new files should be written in swift, and I am seeing an odd problem with using KVC in an Objective-C object to set a property on a Swift object. My Objective-C sets a property like so: [textObject setValue:0.0…
A O
  • 5,516
  • 3
  • 33
  • 68
7
votes
4 answers

Using Predicates on Array Objects in Swift returns Error

When I filter an array of custom Swift classes using a Predicate I get the error: *** NSForwarding: warning: object 0x78ed21a0 of class 'Plantivo1_6.Seed' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector…
Timm Kent
  • 1,123
  • 11
  • 25
7
votes
4 answers

Key-Value Coding (KVC) with Array/Dictionary in Swift

Is it possible to key-value code (KVC) with native Swift data structures such as Array and Dictionary? Key-Value coding is still available for NSFoundation structures within Swift, just like in Objective C. For example, this is valid: var nsarray:…
kev
  • 7,712
  • 11
  • 30
  • 41
7
votes
2 answers

How to create a predicate that compares all properties of an object?

For example, I have an object that has three properties: firstName, middleName, lastName. If I want to search a string "john" in all the properties using NSPredicate. Instead of creating a predicate like: [NSPredicate…
David Liu
  • 16,374
  • 12
  • 37
  • 38
7
votes
3 answers

NSManagedObject subclasses and setValuesForKeysWithDictionary:

I am initializing a NSManagedObject subclass using: - (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues I am also knowingly giving it the undefined keys, which of course should throw an exception. So, I have implemented: -…
Corey Floyd
  • 25,929
  • 31
  • 126
  • 154
7
votes
4 answers

#typedef and KVC in ObjC

I have a class that looks like this: @interface Properties : NSObject { @private NSNumber* prop1; NSNumberBool* prop2; //etc where NSNumberBool is a typedef: // in MyApp_Prefix.pch typedef NSNumber NSNumberBool; I have all the required…
tba
  • 6,229
  • 8
  • 43
  • 63
7
votes
1 answer

Key-Value Coding @UnionOfObjects

I can't figure out what @UnionOfObjects offers that a simple valueForKey: or valueForKeyPath: can't do. Apple docs: The @unionOfObjects operator returns an array containing the distinct objects in the property specified by the key path to the…
Jesse Gumpo
  • 4,777
  • 1
  • 20
  • 29
6
votes
1 answer

setNilValueForKey error

I have four textfields that bind to the model key path. If a number is typed into the textfield, everything works as planned. However, if the number is deleted then I get an error in the console with: [Temperature 0x1003144b0 setNilValueForKey]:…
wigging
  • 8,492
  • 12
  • 75
  • 117
6
votes
2 answers

Helper classes/libraries to make use of KVC/KVO on iOS more practical/safe?

This question is really looking for a specific class that I know exists, but cannot find. A few weeks ago I read through an article outlining a helper class for using KVC - it let you encapsulate KVC subscriptions so that you could have multiple…
1 2
3
25 26