Commits

Anonymous committed 982b4c4

Put the UUID functionality in a category

Comments (0)

Files changed (3)

 //
 
 #import "BWToolbarItem.h"
+#import "NSString+BWAdditions.h"
 
 @interface BWToolbarItem ()
 @property (copy) NSString *identifierString;
 	}
 	
 	if (identifierString == nil || [identifierString isEqualToString:@""])
-	{
-		// Generate a random UUID
-		CFUUIDRef uuidObj = CFUUIDCreate(nil);
-		NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj);
-		CFRelease(uuidObj);
-		[newUUID autorelease];
-		
-		// Set the identifier to the UUID
-		[self _setItemIdentifier:[super itemIdentifier]];
-	}
+		[self _setItemIdentifier:[NSString randomUUID]];
 	else
-	{
 		[self _setItemIdentifier:identifierString];
-	}
 }
 
 - (void)dealloc

NSString+BWAdditions.h

+//
+//  NSString+BWAdditions.h
+//  BWToolkit
+//
+//  Created by Brandon Walkin on 15/12/08.
+//  Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSString (BWAdditions)
+
++ (NSString *)randomUUID;
+
+@end

NSString+BWAdditions.m

+//
+//  NSString+BWAdditions.m
+//  BWToolkit
+//
+//  Created by Brandon Walkin on 15/12/08.
+//  Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSString+BWAdditions.h"
+
+
+@implementation NSString (BWAdditions)
+
++ (NSString *)randomUUID
+{
+	CFUUIDRef uuidObj = CFUUIDCreate(nil);
+	NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj);
+	CFRelease(uuidObj);
+	
+	return [newUUID autorelease];
+}
+
+@end