1.1 --- a/CollectionUtils.m Sat May 24 13:24:33 2008 -0700
1.2 +++ b/CollectionUtils.m Tue May 12 14:38:30 2009 +0200
1.3 @@ -180,6 +180,59 @@
1.4 }
1.5
1.6
1.7 +BOOL kvSetSet( id owner, NSString *property, NSMutableSet *set, NSSet *newSet ) {
1.8 + CAssert(set);
1.9 + if (!newSet)
1.10 + newSet = [NSSet set];
1.11 + if (![set isEqualToSet: newSet]) {
1.12 + [owner willChangeValueForKey: property
1.13 + withSetMutation:NSKeyValueSetSetMutation
1.14 + usingObjects:newSet];
1.15 + [set setSet: newSet];
1.16 + [owner didChangeValueForKey: property
1.17 + withSetMutation:NSKeyValueSetSetMutation
1.18 + usingObjects:newSet];
1.19 + return YES;
1.20 + } else
1.21 + return NO;
1.22 +}
1.23 +
1.24 +
1.25 +BOOL kvAddToSet( id owner, NSString *property, NSMutableSet *set, id objToAdd ) {
1.26 + CAssert(set);
1.27 + if (![set containsObject: objToAdd]) {
1.28 + NSSet *changedObjects = [[NSSet alloc] initWithObjects: &objToAdd count: 1];
1.29 + [owner willChangeValueForKey: property
1.30 + withSetMutation: NSKeyValueUnionSetMutation
1.31 + usingObjects: changedObjects];
1.32 + [set addObject: objToAdd];
1.33 + [owner didChangeValueForKey: property
1.34 + withSetMutation: NSKeyValueUnionSetMutation
1.35 + usingObjects: changedObjects];
1.36 + [changedObjects release];
1.37 + return YES;
1.38 + } else
1.39 + return NO;
1.40 +}
1.41 +
1.42 +
1.43 +BOOL kvRemoveFromSet( id owner, NSString *property, NSMutableSet *set, id objToRemove ) {
1.44 + if ([set containsObject: objToRemove]) {
1.45 + NSSet *changedObjects = [[NSSet alloc] initWithObjects: &objToRemove count: 1];
1.46 + [owner willChangeValueForKey: property
1.47 + withSetMutation: NSKeyValueMinusSetMutation
1.48 + usingObjects: changedObjects];
1.49 + [set removeObject: objToRemove];
1.50 + [owner didChangeValueForKey: property
1.51 + withSetMutation: NSKeyValueMinusSetMutation
1.52 + usingObjects: changedObjects];
1.53 + [changedObjects release];
1.54 + return YES;
1.55 + } else
1.56 + return NO;
1.57 +}
1.58 +
1.59 +
1.60 @implementation NSArray (MYUtils)
1.61
1.62 - (BOOL) my_containsObjectIdenticalTo: (id)object