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
2
votes
2 answers

Core data fetch: Sort by relationship count

I am trying to fetch an entity with the lowest count in one of it's relationships. The entity is called Solution, and this has a to-many relationship called gamesFeaturedIn which links to a Game object. So I am doing this (using the RestKit…
Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
1
vote
2 answers

KVC Compliance - Guidelines for declaring iVars

I have seen ivars that are backing properties declared in 2 general formats (in various books, on blogs, etc...) : myProperty = _myProperty; myProperty = myProperty_; Apple docs say the former one is needed for key value compliance Which one is…
Vinod
  • 93
  • 5
1
vote
2 answers

GRMustache formatted numbers, or an HTML Template Engine with Number Formatting in iOS

I'm not sure how to best go about this. I've tried solving this my own way, but failed so far. I tried using GRMustache, only to realize that I'm trying to display floats that just look hideous in the template I'm trying to use. Basically, I have…
Josh Kovach
  • 7,679
  • 3
  • 45
  • 62
1
vote
1 answer

Trying to use KVC in Xcode to update a TextLabel

I've got a TextField that I'm trying to update the values as it progresses through running my code using KVC. Unfortunately I cannot seem to get anything to update past the initial value. I've used the bindings on the button that launches the code,…
1
vote
3 answers

@synthesized properties and KVC

Should setter generated with @synthesize be KVC compilant or not? I found statement that getters and setters generated are KVC-compliant, shouldn't it call one of this methods? @interface testing : NSObject @property (nonatomic, retain) NSString…
Marcin
  • 3,694
  • 5
  • 32
  • 52
1
vote
1 answer

KVC compliance test

Is there any tool, similar to LLVM's static analyzer, that wil test if an Objective C class is 100% KVC compliant?
cfischer
  • 24,452
  • 37
  • 131
  • 214
1
vote
0 answers

Swift init via KeyPath / WritableKeyPath

Is there any way to initialize a Swift type by setting its properties via Key Path? struct SomeStruct { var number: Int init(to number: Int) { self.number = number // ok } init(viaKeyPathTo number: Int) { …
pkamb
  • 33,281
  • 23
  • 160
  • 191
1
vote
1 answer

Validate "Any" with validateValue: forKey in CoreData

I'm writing to CoreData with key-values: entity.setValue(value: , forKey: ) Before writing to CoreData I store the value and the field name in vars: var value: Any? var field: String I would like to do a simple validation before I…
1
vote
1 answer

Key-value observation weird behavior

Perhaps this question is more general than I will make it seem, but I wanted to make sure I showed my full context in case something there is the cause of this issue. I wrote a singleton class with a KVC-compliant property and two methods: class…
swineone
  • 2,296
  • 1
  • 18
  • 32
1
vote
1 answer

Can you run KVC functions in Xcode Playgrounds?

I'm following a tutorial on KVC and KVO when I attempted to enter the code into a playground however it wouldn't run. I received the error "terminating with uncaught exception of type NSException". I even tried to create a single app application…
Laurence Wingo
  • 3,912
  • 7
  • 33
  • 61
1
vote
1 answer

Using KVC with Singleton pattern

My questionwas about if it was possible to use KVC on a Singleton property on Swift. I was testing KVC on a class was able to get it working but decided to see if it work on a Singleton class. I'm running into an error stating that the "shared"…
victorydub
  • 111
  • 10
1
vote
1 answer

Swift 4 new KVC

I am trying to understand latest addition to Swift 4 - better KVC. Having this simple stuff in playground prints out nothing class Foo { var name: String init(name: String) { self.name = name } } class Bar { var fooObject:…
Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43
1
vote
0 answers

Extend Key-Value Coding for Geometric structures in Swift

As a newbie in macOS programming and in particular with Swift, I’ve been disappointed to discover that the structure’s properties (attributes) do not work with Cocoa Bindings. In my data model (for my convenience) I made extensive use of the…
princi
  • 11
  • 3
1
vote
2 answers

Set the same value for all existing keys in an NSDictionary

In KVC, I usually use setValues:forKeyPath: to set the same value for objects in a collection. E.g.: NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:10]; for (int i = 0; i < 10; i++) { SomeClass *obj = [[SomeClass…
Eddie
  • 1,903
  • 2
  • 21
  • 46
1
vote
1 answer

Swift - `NSUnknownKeyException`: calling `setValue:forKey` on NSObject with optional values in dictionary

The code in the minimal example (so minimal it does not really make sense...) below crashes: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__lldb_expr_345.People 0x60800002a5a0> setValue:forUndefinedKey:]: this…
Sajjon
  • 8,938
  • 5
  • 60
  • 94