* Added kv*Set utility functions for handling KV grunge when mutating an NSSet property.
* Change CFMakeCollectable to NSMakeCollectable.
1.1 --- a/CollectionUtils.h Tue May 05 11:09:06 2009 -0700
1.2 +++ b/CollectionUtils.h Sun May 10 18:57:43 2009 -0700
1.3 @@ -47,6 +47,10 @@
1.4 void setString( NSString **var, NSString *value );
1.5 BOOL ifSetString( NSString **var, NSString *value );
1.6
1.7 +BOOL kvSetSet( id owner, NSString *property, NSMutableSet *set, NSSet *newSet );
1.8 +BOOL kvAddToSet( id owner, NSString *property, NSMutableSet *set, id objToAdd );
1.9 +BOOL kvRemoveFromSet( id owner, NSString *property, NSMutableSet *set, id objToRemove );
1.10 +
1.11
1.12 #define $true ((NSNumber*)kCFBooleanTrue)
1.13 #define $false ((NSNumber*)kCFBooleanFalse)
2.1 --- a/CollectionUtils.m Tue May 05 11:09:06 2009 -0700
2.2 +++ b/CollectionUtils.m Sun May 10 18:57:43 2009 -0700
2.3 @@ -180,6 +180,59 @@
2.4 }
2.5
2.6
2.7 +BOOL kvSetSet( id owner, NSString *property, NSMutableSet *set, NSSet *newSet ) {
2.8 + CAssert(set);
2.9 + if (!newSet)
2.10 + newSet = [NSSet set];
2.11 + if (![set isEqualToSet: newSet]) {
2.12 + [owner willChangeValueForKey: property
2.13 + withSetMutation:NSKeyValueSetSetMutation
2.14 + usingObjects:newSet];
2.15 + [set setSet: newSet];
2.16 + [owner didChangeValueForKey: property
2.17 + withSetMutation:NSKeyValueSetSetMutation
2.18 + usingObjects:newSet];
2.19 + return YES;
2.20 + } else
2.21 + return NO;
2.22 +}
2.23 +
2.24 +
2.25 +BOOL kvAddToSet( id owner, NSString *property, NSMutableSet *set, id objToAdd ) {
2.26 + CAssert(set);
2.27 + if (![set containsObject: objToAdd]) {
2.28 + NSSet *changedObjects = [[NSSet alloc] initWithObjects: &objToAdd count: 1];
2.29 + [owner willChangeValueForKey: property
2.30 + withSetMutation: NSKeyValueUnionSetMutation
2.31 + usingObjects: changedObjects];
2.32 + [set addObject: objToAdd];
2.33 + [owner didChangeValueForKey: property
2.34 + withSetMutation: NSKeyValueUnionSetMutation
2.35 + usingObjects: changedObjects];
2.36 + [changedObjects release];
2.37 + return YES;
2.38 + } else
2.39 + return NO;
2.40 +}
2.41 +
2.42 +
2.43 +BOOL kvRemoveFromSet( id owner, NSString *property, NSMutableSet *set, id objToRemove ) {
2.44 + if ([set containsObject: objToRemove]) {
2.45 + NSSet *changedObjects = [[NSSet alloc] initWithObjects: &objToRemove count: 1];
2.46 + [owner willChangeValueForKey: property
2.47 + withSetMutation: NSKeyValueMinusSetMutation
2.48 + usingObjects: changedObjects];
2.49 + [set removeObject: objToRemove];
2.50 + [owner didChangeValueForKey: property
2.51 + withSetMutation: NSKeyValueMinusSetMutation
2.52 + usingObjects: changedObjects];
2.53 + [changedObjects release];
2.54 + return YES;
2.55 + } else
2.56 + return NO;
2.57 +}
2.58 +
2.59 +
2.60 @implementation NSArray (MYUtils)
2.61
2.62 - (BOOL) my_containsObjectIdenticalTo: (id)object
3.1 --- a/MYErrorUtils.m Tue May 05 11:09:06 2009 -0700
3.2 +++ b/MYErrorUtils.m Sun May 10 18:57:43 2009 -0700
3.3 @@ -140,7 +140,7 @@
3.4 #if USE_SECURITY_API
3.5 result = (id) SecCopyErrorMessageString(code,NULL);
3.6 if (result) {
3.7 - [(id)CFMakeCollectable(result) autorelease];
3.8 + [NSMakeCollectable(result) autorelease];
3.9 if ([result hasPrefix: @"OSStatus "])
3.10 result = nil; // just a generic message
3.11 }