Key value coding and many relationships

I am a bit confused about the encoding of key values ​​and many relationships. I read that, having such a relationship, I should use [object mutableArrayValueForKey: @ "key"]; retrieve a mutable array that contains objects in this ordered relationship.

I don't understand what is the difference between mutableArrayValueForKey or just valueForKey.

Let me illustrate an example (an array is an NSMutableArray self-tuning as a property):

id array1= [self valueForKey:@"array"];

NSLog(@"first element %@",[array1 objectAtIndex:1]);

id array2 = [self mutableArrayValueForKey:@"array"];

NSLog(@"first element %@",[array2 objectAtIndex:1]);

Both calls return exactly the same. In this case, what good or the other of the second?

Hooray!

+3
source share
2 answers

mutableArrayValueForKey "", "". , :

NSLog(@"%@", [self.array class]);
NSLog(@"%@", [[self valueForKey:@"array"] class]);
NSLog(@"%@", [[self mutableArrayValueForKey:@"array"] class]);

:

2010-02-24 20:06:44.258 Untitled[25523:a0f] NSCFArray
2010-02-24 20:06:44.275 Untitled[25523:a0f] NSCFArray
2010-02-24 20:06:44.276 Untitled[25523:a0f] NSKeyValueSlowMutableArray

documentation mutableArrayValueForKey , -. NSMutableArray ivar. , ? KVC ivar, countOf<Key> objectIn<Key>AtIndex:. , "" ivar, KVC.

, NSMutableArray, NSMutableArray? mutableArrayValueForKey. -, KVC- , mutating to-many , insertObject:in<Key>AtIndex:.

, ivar ( ), , , .

+6

objectAtIndex:0, objectAtIndex:1.

, , addObject: removeObjectAtIndex:, @"array" .

0

Source: https://habr.com/ru/post/1734342/


All Articles