key-value-coding

Swift: “This class is not key value coding-compliant…” for Double values

我只是一个虾纸丫 提交于 2019-12-09 13:44:44
问题 I have a scenario in which I have a simple data object in Swift, containing multiple property variables. They are a mix of String? and Double? value types. I'm trying to retrieve the values for each property using valueForKey . My code looks something like this... let myDataObj = ... let stringKeyName = "myStringProperty" let doubleKeyName = "myDoubleProperty" guard let stringPropertyValue = myDataObj.valueForKey(stringKeyName) else { return } guard let doublePropertyValue = myDataObj

How to add an object to a programatically bound NSMutableArray?

ⅰ亾dé卋堺 提交于 2019-12-08 04:15:54
问题 I have an NSDocument which has the following structure: @interface MyDocument : NSDocument { NSMutableArray *myArray; IBOutlet NSArrayController *myArrayController; IBOutlet MyView *myView; } @end I instantiate the NSArrayController and the MyView in MyDocument.xib, and have made the connections to the File's Owner (MyDocument), so I am pretty sure that from the point of view of Interface Builder, I have done everything correctly. The interface for MyView is simple: @interface MyView : NSView

Cocoa bindings problem; bound table columns don't show any data, no errors in console

别等时光非礼了梦想. 提交于 2019-12-08 02:32:17
问题 I'm having trouble converting my Cocoa project from a manually-synched interface model to a bindings model so that I don't have to worry about interface glue code. I followed the CocoaDevCentral Cocoa Bindings tutorial to make sure that I had covered all the bases, but things aren't working correctly. I have a master-detail interface, but I'm having trouble even getting the master portion of the interface to work correctly. No data is showing up in the master column, even though I've set up

How to handle '[<__NSCFString 0x2f1730> valueForUndefinedKey:]: this class is not key value coding-compliant for the key $oid' error

一曲冷凌霜 提交于 2019-12-08 01:32:22
问题 I am hitting the error (stated in the subject) because there are times the property 'id' does not store the hash containing '$oid' in the returned json. For example Sometimes I get: "id":{"$oid":"4eea972209f47a0028000140"} Some other times I get "id":"4eea972209f47a0028000140" I am trying to do a check in the following code to cater for such irregularity if ([[question valueForKey:@"id"] valueForKey:@"$oid"]) { question_id = [[question valueForKey:@"id"] valueForKey:@"$oid"]; } else {

Generate a complete list of key-value coding paths for nested NSDictionary's?

可紊 提交于 2019-12-07 13:04:54
问题 I have an NSDictionary that contains keys and values, and some values will also be NSDictionary s... to an arbitrary (but reasonable) level. I would like to get a list of all valid KVC paths, e.g. given: { "foo" = "bar", "qux" = { "taco" = "delicious", "burrito" = "also delicious", } } I would get: [ "foo", "qux", "qux.taco", "qux.burrito" ] Is there a simple way to do this that already exists? 回答1: You could recurse through allKeys . A key is a key path, obviously, and then if the value is

Read file and get key=value without using java.util.Properties

∥☆過路亽.° 提交于 2019-12-07 12:03:19
问题 I'm building a RMI game and the client would load a file that has some keys and values which are going to be used on several different objects. It is a save game file but I can't use java.util.Properties for this (it is under the specification). I have to read the entire file and ignore commented lines and the keys that are not relevant in some classes. These properties are unique but they may be sorted in any order. My file current file looks like this: # Bio playerOrigin=Newlands

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

北城余情 提交于 2019-12-07 01:43:52
问题 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 forKey:@"fontSize"] My Swift object ( textObject ) has a custom setter/getter for this property. var fontSize: CGFloat? { get { return internalTextGraphic?.fontSize } set { internalTextGraphic?.fontSize = newValue } } However, if I set a breakpoint in the set ,

NSManagedObject subclasses and setValuesForKeysWithDictionary:

﹥>﹥吖頭↗ 提交于 2019-12-07 00:22:47
问题 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: - (void)setValue:(id)value forUndefinedKey:(NSString *)key If a key is undefined, I map it to the correct key. However, my implementation never gets called, instead NSManagedObject 's implementation is used, which in turn still throws an exception. Is there a

What steps should be taken to convert my XML into Core Data objects?

感情迁移 提交于 2019-12-06 12:10:25
问题 I have an XML file which contains lists of stores, a simplified version is below. What I would like help with is some high-level ideas on the simplest ways to move this data into objects for storage in Core Data. I see suggestions around key-value pairs but as you can see in my example below, I have child elements with the same name/key and there can be an arbitrary number of these for each store element. I intend to store these objects within the app for future use (they will be annotations

Cocoa bindings problem; bound table columns don't show any data, no errors in console

时光怂恿深爱的人放手 提交于 2019-12-06 10:43:31
I'm having trouble converting my Cocoa project from a manually-synched interface model to a bindings model so that I don't have to worry about interface glue code. I followed the CocoaDevCentral Cocoa Bindings tutorial to make sure that I had covered all the bases, but things aren't working correctly. I have a master-detail interface, but I'm having trouble even getting the master portion of the interface to work correctly. No data is showing up in the master column, even though I've set up the bindings model similar to how it is shown in the tutorial. I've made sure all my controllers and