key-value-coding

Cocoa KVC: “class is not key value coding-compliant”

空扰寡人 提交于 2019-12-24 05:22:07
问题 I'm trying to update some properties with KVC. The properties have been synthesized. This line works: myObject.value = intValue; This doesn't work: [self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"]; And blows up with: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyViewController 0xd1cec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myObject.value.' Yet further up the method (awakeFromNib) other

NSMutableDictionary remove object at key path?

本秂侑毒 提交于 2019-12-22 14:48:40
问题 I've got a layered NSMutableDictionary object and i'd like to be able to remove dictionaries deeper down in the hierarchy. Is there a quick and easy way to do this, for example, a removeObjectAtKeyPath-like method? Can't seem to find one. Thanks! 回答1: Nothing built in, but your basic category method will do just fine: @implementation NSMutableDictionary (WSSNestedMutableDictionaries) - (void)WSSRemoveObjectForKeyPath: (NSString *)keyPath { // Separate the key path NSArray * keyPathElements =

Key-value observing on UIButton's State

这一生的挚爱 提交于 2019-12-22 04:29:29
问题 UIButton has a state property, which appears to be KVO compliant by all accounts and there is no documentation to indicate otherwise. However, when I added an observer to a UIButton's state property, the observer callback was never invoked. How come? 回答1: If you look at the documentation of UIControl, the state property is marked: synthesized from other flags. I guess this is why changes to this property are not KVO compliant. However, you can simply register and observer for the values you

Does a Core Data NSSet contain an object with a certain ID?

我是研究僧i 提交于 2019-12-22 01:16:19
问题 I have a Core Data object that contains an NSSet of other objects (e.g. Library object contains NSSet of Books). What's the best way to check if an instance of Library contains a book with a certain bookID? Is it possible to be done with Key Value coding or do I have to enumerate all books and check them manually? 回答1: Yes, you can use KVC for this. BOOL bookExists = [[set valueForKey:@"bookID"] containsObject:@"myBookID"]; 来源: https://stackoverflow.com/questions/7256909/does-a-core-data

How can I use KVO on SKSpriteNode position property

廉价感情. 提交于 2019-12-21 20:15:29
问题 I would like to use KVO to observe changes to the SKSpriteNode position property, but it doesn't seem to work. Is SKNode's position property observable? 回答1: Nope, it is not. SK behind the scenes is a C++ engine that bypasses most of Objective-C's overhead, like for instance KVO (KVC will still work cause that's entirely on you). Unlike in UI(Kit) apps, most values of most objects change often anyway, so if you're interested in changes to a property it's faster to simply check it every frame

KVO rocks. Now how do I use it asynchronously?

北慕城南 提交于 2019-12-21 05:22:26
问题 I am sold on KVO but if used in the obvious way it is synchronous. I would like to use it in a situation where I am firing off many KVO messages in rapid succession and it is causing my app to grind to a halt as the KVO messages are handled. Can someone suggest an approach - perhaps using NSOperation or NSThread - that will work here? My goal is to retain the decoupled, flexibility of KVO if possible. 回答1: Check out NSNotification. It's not quite the same thing, but you can fire off

Cocoa Key Value Bindings: What are the explanations of the various options for Controller Key?

允我心安 提交于 2019-12-20 09:24:14
问题 When I bind a control to an NSArrayController using Interface Builder, there are a variety of options under the "Controller Key" field in the bindings inspector. I understand what "arrangedObjects" is, and I semi-understand what "selection" is, but I'd love to see a really nice explanation of all the options and when to use each one. The list includes: selectionIndexes, selectionIndex, selectedObject, sortDescriptors, etc. I haven't been able to find a good explanation of these options. I'm

Cocoa Key Value Bindings: What are the explanations of the various options for Controller Key?

﹥>﹥吖頭↗ 提交于 2019-12-20 09:23:33
问题 When I bind a control to an NSArrayController using Interface Builder, there are a variety of options under the "Controller Key" field in the bindings inspector. I understand what "arrangedObjects" is, and I semi-understand what "selection" is, but I'd love to see a really nice explanation of all the options and when to use each one. The list includes: selectionIndexes, selectionIndex, selectedObject, sortDescriptors, etc. I haven't been able to find a good explanation of these options. I'm

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

久未见 提交于 2019-12-19 03:19:05
问题 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. 回答1: The Controller Key pop-up menu is a way to help you discover what keys the controller (typically a NSArrayController, NSObjectController or a NSTreeController) presents. The best example is the selection key of NSArrayControllers, which contains the set of selected objects. What is confusing is the NSObjectController presents a 'selection' key too, although the

Getting Max Date from NSArray, KVC

喜夏-厌秋 提交于 2019-12-18 17:48:33
问题 I've got an array of NSDates and I'd like to grab the largest NSDate from the array. While i could always sort them and grab the first/last, is there a way to do this with KeyValueCoding or some other quick one liner kind of way? I know that I could use something like valueForKeyPath@"@max.date" if the objects had a date property, but what if the objects are dates themselves?? thanks 回答1: You can use, NSDate *maxDate = [dateArray valueForKeyPath:@"@max.self"]; This will give you the largest