Questions tagged [kvc]

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.

References

193 questions
3
votes
6 answers

Key Value Coding vs accessor methods in iOS

I'm trying to understand some theory part in Objective C related to KVC. Following is the example I've done. I'm having class call Cookie and it has a property like below @property NSString *name; Next, I have another class call Person and it has…
AnujAroshA
  • 4,623
  • 8
  • 56
  • 99
3
votes
1 answer

Model Key Path With Multiple Properties

Here, I'm using an NSArrayController to bind properties from Core Data entities into the value of text view table cells. What syntax do I use to access multiple properties of the entity in the Model Key Path? Example as a format string: @"%@, %@",…
The Kraken
  • 3,158
  • 5
  • 30
  • 67
3
votes
1 answer

Can valueForKeyPath compute the maximum of sums?

I have the following Objective-C class: @interface GraphDataPoint : NSObject @property NSDate *date; @property NSNumber *value; @end Given an NSArray of GraphDataPoint, I know how to calculate the maximum value using [data…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3
votes
1 answer

mutableArrayValueForKey NSMutableArray crash when removing objects

I'm running into a crash with the following code. self.items is an NSArray of NSManagedObjects with an "id" attribute of type String: NSMutableArray *allIDs = [self.items mutableArrayValueForKey:@"id"]; NSArray *presentIDs = // a subset of…
James Kuang
  • 10,710
  • 4
  • 28
  • 38
3
votes
3 answers

How can I access non-KVC compliant properties with just their name?

Context: I have several CGPathRef's in a custom class, derived from NSObject, named model. I'm looking for a way to return a specific CGPathRef, based one a string I generate at runtime. Simplified Example, if I could use KVC: #model.h @property…
Emin Israfil iOS
  • 1,801
  • 1
  • 17
  • 26
3
votes
1 answer

Mapping NSDictionary to NSObject subclass

I'm working on cline-server app. I'm getting JSON objects as response from the server, then I'm converting JSON to NSDictionary. Now I need to map NSDictionary to custom data object. So I have created BasicDataObject class that has: #pragma mark -…
Nikita
  • 1,811
  • 1
  • 20
  • 41
3
votes
3 answers

Nested NSArray filtering

I have the need to obtain the maximum value of a property of a collection of custom objects of the same class. The objects are stored in a NSArray, and the property happens to be another NSArray of numbers. Let me explain in detail: NSArray…
Juan Catalan
  • 2,299
  • 1
  • 17
  • 23
3
votes
1 answer

ios, KVC, why doesn't it invoke countOf when i invoke [[MyObject valueForKey:"MyArray" ] count]

.................. Environment:OSX10.8, Xcode4.5 Reference: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual /KeyValueCoding/Articles/SearchImplementation.html#//apple_ref/doc/uid /20000955-CJBBBFFA …
MarcusHe
  • 31
  • 2
3
votes
1 answer

Objective-C KVC changes the type of property

I'm new to Objective-c. I'm writing a simple method to convert a dictionary to a object to practice the KVC knowledge: +(id) ConvertDictionary:(NSDictionary *)dict ToClassInstance:(Class)type{ id targetObj =…
3
votes
1 answer

Efficiently getting an object's attributes or enforcing declaration of class attribute

BACKGROUND SETTING I am trying to create a library for accessing and caching web service data in Android and have stumbled across a problem. All the objects managed by my library inherit from a base Entity class. Any derivate class of Entity can…
lucian.pantelimon
  • 3,673
  • 4
  • 29
  • 46
3
votes
1 answer

How to bind to NSArrayController's arranged objects

I would like to programmatically bind a custom class (MyClass) array to an array controller (NSArrayController) with its content bound to another array (modelArray). MyClass displays the content of the array, like a NSTableView. My problem is: how…
trfd
  • 93
  • 1
  • 7
3
votes
1 answer

Is this object KVC-compliant?

I'm trying to understand how to use Bindings in Xcode. I have this class: #import @interface OddsItem : NSObject { NSMutableDictionary *properties; } @property(nonatomic, retain) NSMutableDictionary…
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
2
votes
1 answer

KVO/KVC crash on reloading previously unloaded bundles

I'm running into an issue with loadable bundles and KVO. It seems that any class that has KVO observers attached to an instance of it cannot be safely be unloaded via NSBundle's -unload method. I'm doing the following: for (int i = 0; i < 100;…
joerick
  • 16,078
  • 4
  • 53
  • 57
2
votes
2 answers

Problems on NSArray's -valueForKey: when its item is NSDictionary

I have an array which contains items of NSDictionary, I want to transform the items to other objects, my first thought is valueForKey:, so I add a category method toMyObject for NSDictionary, and call for: [array valueForKey:@"toMyObject"] But it…
cxa
  • 4,238
  • 26
  • 40
2
votes
1 answer

Key-Value Coding with custom getter, setter and ivar

I'm wondering how Key-Value Coding, to access a property value, works in Objective-C when this property has a custom getter, setter and ivar defined. According to Accessor Search Patterns the runtime will first search for a getter method and fall…
DennisFrett
  • 121
  • 1
1 2
3
12 13