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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also discovered
@set
: