Created
November 23, 2012 08:39
-
-
Save n-b/4134555 to your computer and use it in GitHub Desktop.
More KVC weirdness with NSOrderedSets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// clang orderedsets-more-kvc.m -framework Foundation && ./a.out | |
// | |
#import <Foundation/Foundation.h> | |
int main () | |
{ | |
@autoreleasepool { | |
id data = (@[ | |
@{ @"values": [NSOrderedSet orderedSetWithArray:@[@1, @2, @3, @4]] }, | |
@{ @"values": [NSOrderedSet orderedSetWithArray:@[@1, @3, @5, @7]] } | |
]); | |
// valueForKeyPath logs an error, but somehow manages to return the correct result. | |
NSLog(@"union : %@",[data valueForKeyPath:@"@distinctUnionOfArrays.values"]); | |
/* | |
2012-11-23 09:34:47.507 a.out[12956:707] *** -[NSMutableArray addObjectsFromArray:]: array argument is not an NSArray | |
2012-11-23 09:34:47.509 a.out[12956:707] *** -[NSMutableArray addObjectsFromArray:]: array argument is not an NSArray | |
2012-11-23 09:34:47.509 a.out[12956:707] union : ( | |
5, | |
1, | |
2, | |
7, | |
3, | |
4 | |
) | |
*/ | |
// Convert each OrderedSet to an Array to mute the error. | |
NSLog(@"union : %@",[data valueForKeyPath:@"@distinctUnionOfArrays.values.@array"]); | |
/* | |
2012-11-23 09:34:41.930 a.out[12927:707] union : ( | |
5, | |
1, | |
2, | |
7, | |
3, | |
4 | |
) | |
*/ | |
} | |
return 0; | |
} |
Also discovered @set
:
[data valueForKeyPath:@"@distinctUnionOfSets.values.@set"]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have any idea where this
@array
operator comes from or why it needs to be in the last position? I can't find any mention of such an operator; there's thearray
property onNSOrderedSet
, but that doesn't work as part of the path without the@
. Very strange.If you have a Stack Overflow account and any insight into this issue, please have a look at http://stackoverflow.com/questions/31780983/extracting-properties-from-nsarray-of-nsarray-of-nsdictionary/