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
5
votes
0 answers

Cocoa, binding across 'To-Many' relationships

I have a model which is essentially three entities: Manufacturers <---->> Models <---->> Cars The Manufacturer entity has property 'name' The Model entity has property 'name' The Car entity has properties 'registration' and 'milage' I have a table…
Quantum_Oli
  • 267
  • 2
  • 10
5
votes
1 answer

KVO on removeAllObjects Triggers NSKeyValueChangeRemoval for each Item Separately

I'm watching an NSArray property with KVO. I've implemented KVC like in this post and I also implemented most of the KVC array accessors. To mutate it, I use mutableArrayValueForKey. It works fine, except to 2 issues: When I call removeAllObjects,…
fabb
  • 11,660
  • 13
  • 67
  • 111
5
votes
2 answers

Getting the min/max coordinates of NSValue transformed CGPoints in an NSArray using KVC

I recently read some documentation and some blog entries about Key-Value Coding and found it extremely useful. I want to utilize it for my case, but I haven't been successful so far. In my case, I have an NSMutableArray containing CGPoint's…
tolgamorf
  • 809
  • 6
  • 23
4
votes
3 answers

How do I use Key-Value Coding in Swfit 4.0?

I never used Swift4 before, and dont know how to use KVC in it. I try to create model with Dictionary, here the code: class Person : NSObject { var name: String = "" var age: Int = 0 init(dict: [String : Any]) { super.init() …
Ben
  • 51
  • 1
  • 6
4
votes
1 answer

XCode 9 issue. Failed to set user defined property in interface builder

My issue is that settings a keypath and value in interface builder does not seem to be working in XCode 9. There is a work around where you make the variable inspectable. I've created a sample project and details below. I created a simple test…
Yogurt
  • 2,913
  • 2
  • 32
  • 63
4
votes
1 answer

BOOL property KVC: is this behavior a bug?

It appears that valueForKey: with a BOOL @property name for the key returns different types (and, consequently, leads to different JSON serializations) on 64-bit and 32-bit iOS systems: On 32-bit (iPhone 4s simulator): 8 * sizeof(void*) =…
Isaac
  • 10,668
  • 5
  • 59
  • 68
4
votes
2 answers

Why does setValue:forKey: fail on a 32-bit system but not 64-bit?

I recently submitted a bug report to Apple about this, but I thought I would ask the question anyways in case I'm missing something obvious. In Objective-C, the following call works fine on a 64-bit system but throws an NSInvalidArgumentException on…
Greg Brown
  • 3,168
  • 1
  • 27
  • 37
4
votes
3 answers

How to check if an id points to a CGRect?

Supposing we have: id value = [self valueForKey:@"frame"]; BOOL valueIsCGRect = ???; How can I decide? Should I cast id to something?
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
4
votes
3 answers

Filter Array of Objects with NSPredicate based on NSInteger property in super class

I've got the following setup: @interface Item : NSObject { NSInteger *item_id; NSString *title; UIImage *item_icon; } @property (nonatomic, copy) NSString *title; @property (nonatomic, assign) NSInteger *item_id; @property (nonatomic,…
Gidogeek
  • 1,277
  • 2
  • 16
  • 27
4
votes
3 answers

Initialize instance variables as key/value pair from NSDictionary?

I have my NSObject subclass's public interface defined as, @interface MyObject : NSObject { NSString *_key1; NSString *_key2; NSString *_key3; } - (id)initWithDict:(NSDictionary *)dict; @end Is there are trick to implement the…
emdog4
  • 1,975
  • 3
  • 20
  • 25
4
votes
1 answer

Custom accessor method in Core Data, why using KVO?

A typical custom accessor method could be written as the following: - (NSString *)name { [self willAccessValueForKey:@"name"]; NSString *myName = [self primitiveName]; [self didAccessValueForKey:@"name"]; return myName; } -…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
3
votes
2 answers

KVO on singleton property?

Hi all I'm trying to implement KVO on one of the string properties within a Singleton class. I'm currently running into some errors when trying to add an observer and was hoping that someone could tell me what I'm doing wrong. The below shows my…
victorydub
  • 111
  • 10
3
votes
1 answer

Flatten an array of dictionaries with KVC

I'm trying to flatten a two dimensional array of dictionaries with the use of KVC. NSArray *toBeFlatten = @[@[@{@1:@1}],@[@{@2:@2}]]; NSArray *flat = [toBeFlatten valueForKeyPath:@"@unionOfArrays.self"]; // flat:@[NSNull.null, NSNull.null]; Why are…
melbic
  • 11,988
  • 5
  • 33
  • 37
3
votes
0 answers

KVC Swift 2.1 Reflection

I'm attempting to implement a KVC equivalent is Swift (inspired by David Owens) using reflection. valueForKey is fairly trivial, using reflection to get all the children names and retrieve the appropriate value. setValueForKey has proved to be quite…
barndog
  • 6,975
  • 8
  • 53
  • 105
3
votes
0 answers

@distinctUnionOfOrderedSets equivalent to @distinctUnionOfArrays

I have an array of foos and each foo has a NSOrderedSet of bars. I want to get an array of all the distinct existent bars ids (each bar has a property called objectID). Since there is no @distinctUnionOfOrderedSets I can do it with: [foos…
Flores Robles
  • 656
  • 7
  • 14
1
2
3
12 13