Skip to content

Instantly share code, notes, and snippets.

@jdriscoll
Last active August 29, 2015 14:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jdriscoll/11097729 to your computer and use it in GitHub Desktop.
Mutable objects in set
#import <Foundation/Foundation.h>
void logIt(NSSet *set) {
NSLog(@"set: %@", set);
for (id object in set) {
NSLog(@"element with hash: %lu", (unsigned long)[object hash]);
}
}
int main(int argc, char *argv[]) {
NSMutableString *a = [@"a" mutableCopy];
NSMutableString *b = [@"b" mutableCopy];
NSSet *set = [NSSet setWithObjects:a, b, nil];
logIt(set);
[b setString:@"a"];
logIt(set);
}
2014-04-19 17:14:15.877 Untitled 2[98114:507] set: {(
a,
b
)}
2014-04-19 17:14:15.879 Untitled 2[98114:507] element with hash: 1062
2014-04-19 17:14:15.879 Untitled 2[98114:507] element with hash: 1065
2014-04-19 17:14:15.880 Untitled 2[98114:507] set: {(
a,
a
)}
2014-04-19 17:14:15.880 Untitled 2[98114:507] element with hash: 1062
2014-04-19 17:14:15.880 Untitled 2[98114:507] element with hash: 1062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment