key-value-coding

KVC with NSArrays of NSArrays

廉价感情. 提交于 2019-12-06 08:05:23
问题 I have an array of arrays that I want to use KVC on (at least I think I do -- it seems like the most straightforward way) but I can't figure out how to create keypaths for individual array indexes. My array looks like this NSArray [ NSArray[0, 1, 2, 3], NSArray[4, 5, 6, 7], NSArray[8, 9, 10, 11] ] What I want to do is get the maximum value of index 3 in the inner array. It seems like something like [outerArray valueForKey:@"@max.[3]"] would work, but I can't figure out the syntax, and my

RESTKit: Comparing GET object with locally persisted before overwriting

一个人想着一个人 提交于 2019-12-06 06:58:32
I have a saved object (persisted) in Core Data. Lets say below are the values: //Entity: employee objectID: 1111 firstName: @"Jon" lastName: @"D" modified: @"10:45PM" Now, I do a RKManagedObjectRequestOperation *operation request. I set operation.savesToPersistentStore = NO; and start the operation. The object was downloaded and it's been modified to the following: //Entity: employee objectID: 1111 firstName: @"Jonathan" lastName: @"Doe" modified: @"10:55PM" //I have 15 other properties that are either Strings, NSDate, NSNumber, and BOOLs I believe at this time the modified object is in the

Performance hit incurred using NSMutableDictionary vs. NSMutableArray>

一笑奈何 提交于 2019-12-06 05:36:49
问题 I am considering using an NSMutableDictionary in place of my current NSMutableArray. This is primarily for KVC/KVO reasons. The collection will undergo heavy mutation within the inner loop of my drawing method. Can I expect to incur a significant performance hit if I go ahead with this replacement? Cheers, Doug 回答1: The only way to be sure is to measure. None of us have enough knowledge about how NSMutableDictionary's and NSMutableArray's implementations work, so there's little point asking.

How to test property existence and type based on NSString typed key?

让人想犯罪 __ 提交于 2019-12-06 03:31:14
问题 In my quest to update a Core Data model within my iOS project, I'm querying a server for JSON objects that correspond - to some extent - with the managed entities of my model. The end result I'm striving for is a reliable update solution from JSON output. For the examples in this question, I'll name the core data managed object existingObj and the incoming JSON deserialized dictionary updateDict . The tricky part is dealing with these facts: Not all properties of the existingObj are present

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

北城余情 提交于 2019-12-05 19:16:45
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 playerClass=Warlock # Armor playerHelmet=empty playerUpperArmor=armor900 playerBottomArmor=armor457 playerBoots

NSManagedObject subclasses and setValuesForKeysWithDictionary:

帅比萌擦擦* 提交于 2019-12-05 05:36:29
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 behavior (or bug) that prevents setValuesForKeysWithDictionary: from using any NSManagedObject subclass

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

不羁岁月 提交于 2019-12-05 04:59:33
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 , it never gets hit. I have Objective-C objects that also get this same call, and I just implement

Properties on CALayer subclass aren't getting observed by CATransaction

回眸只為那壹抹淺笑 提交于 2019-12-05 04:29:49
问题 I have a subclass of CALayer with a custom property, declared as such: @interface MyLayer : CALayer @property (nonatomic,retain) NSNumber *customValue; @end @implementation MyLayer @synthesize customValue = _customValue; @end I want to animate this property inside of an explicit CATranasction , so i set up a delegate with the actionForLayer:forKey: method implemented which returns an animation, however any changes to someMyLayerInstance.customValue inside of [CATransaction begin] ...

Why does valueForKey: on a UITextField throws an exception for UITextInputTraits properties?

☆樱花仙子☆ 提交于 2019-12-05 03:06:34
Running this: @try { NSLog(@"1. autocapitalizationType = %d", [self.textField autocapitalizationType]); NSLog(@"2. autocapitalizationType = %@", [self.textField valueForKey:@"autocapitalizationType"]); } @catch (NSException *exception) { NSLog(@"3. %@", exception); } Outputs this: 1. autocapitalizationType = 0 3. [<UITextField 0x6c15df0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key autocapitalizationType. I was expecting: 1. autocapitalizationType = 0 2. autocapitalizationType = 0 This exception only happens with properties that are part of the

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

£可爱£侵袭症+ 提交于 2019-12-04 19:35:52
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? Yes, you can use KVC for this. BOOL bookExists = [[set valueForKey:@"bookID"] containsObject:@"myBookID"]; 来源: https://stackoverflow.com/questions/7256909/does-a-core-data-nsset-contain-an-object-with-a-certain-id