Permalink
Browse files

UUID class and a few little changes. Also, iPhone Simulator target.

  • Loading branch information...
millenomi committed Mar 24, 2009
1 parent 82c249d commit 9f8e363d6a158b01dbbf22f2f32d9aa385de0765
Showing with 321 additions and 5 deletions.
  1. +52 −0 L0UUID.h
  2. +118 −0 L0UUID.m
  3. +13 −0 MuiKit.h
  4. +138 −5 MuiKit.xcodeproj/project.pbxproj
View
@@ -0,0 +1,52 @@
+//
+// L0UUID.h
+// Orma
+//
+// Created by ∞ on 12/08/08.
+// Copyright 2008 Emanuele Vulcano. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreFoundation/CoreFoundation.h>
+
+@interface L0UUID : NSObject <NSCopying, NSCoding> {
+ __strong CFUUIDRef uuid;
+}
+
+// Creates a newly generated UUID.
+- (id) init;
+
+// Creates a UUID that wraps an existing Core Fondation UUID object.
+- (id) initWithUUID:(CFUUIDRef) uuid;
+
+// Creates a UUID from a correctly formatted string.
+- (id) initWithString:(NSString*) string;
+
+// Creates a UUID from the given bytes. They will be copied.
+- (id) initWithBytes:(CFUUIDBytes*) bytes;
+
+// Creates a UUID from the contents of NSData, which must wrap a
+// CFUUIDBytes structure.
+- (id) initWithData:(NSData*) data;
+
+// Retrieves the wrapped Core Foundation UUID object.
+- (CFUUIDRef) CFUUID;
+
+// Returns a string of the kind '68753A44-4D6F-1226-9C60-0050E4C00067' for
+// this UUID.
+@property(readonly) NSString* stringValue;
+
+// Returns the bytes this UUID is made of.
+@property(readonly) CFUUIDBytes UUIDBytes;
+
+// Returns a NSData object wrapping what would be returned by
+// a call to -bytes.
+@property(readonly) NSData* dataValue;
+
++ (id) UUID;
++ (id) UUIDWithUUID:(CFUUIDRef) uuid;
++ (id) UUIDWithString:(NSString*) string;
++ (id) UUIDWithBytes:(CFUUIDBytes*) bytes;
++ (id) UUIDWithData:(NSData*) data;
+
+@end
View
118 L0UUID.m
@@ -0,0 +1,118 @@
+//
+// L0UUID.m
+// Orma
+//
+// Created by ∞ on 12/08/08.
+// Copyright 2008 Emanuele Vulcano. All rights reserved.
+//
+
+#import "L0UUID.h"
+
+
+@implementation L0UUID
+
+- (id) init {
+ CFUUIDRef ref = CFUUIDCreate(kCFAllocatorDefault);
+ self = [self initWithUUID:ref];
+ CFRelease(ref);
+ return self;
+}
+
+- (id) initWithUUID:(CFUUIDRef) u {
+ if (self = [super init])
+ uuid = CFMakeCollectable(CFRetain(u));
+
+ return self;
+}
+
+- (id) initWithString:(NSString*) string {
+ CFUUIDRef ref = CFUUIDCreateFromString(kCFAllocatorDefault, (CFStringRef) string);
+ self = [self initWithUUID:ref];
+ CFRelease(ref);
+ return self;
+}
+
+- (id) initWithData:(NSData*) data {
+ return [self initWithBytes:(CFUUIDBytes*) [data bytes]];
+}
+
+- (id) initWithBytes:(CFUUIDBytes*) bytes {
+ CFUUIDRef ref = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *bytes);
+ self = [self initWithUUID:ref];
+ CFRelease(ref);
+ return self;
+}
+
+- (CFUUIDRef) CFUUID {
+ return uuid;
+}
+
+- (NSString*) stringValue {
+ CFStringRef r = CFUUIDCreateString(kCFAllocatorDefault, uuid);
+ return [(NSString*)r autorelease];
+}
+
+- (NSData*) dataValue {
+ CFUUIDBytes b = CFUUIDGetUUIDBytes(uuid);
+ NSData* d = [[NSData alloc] initWithBytes:&b length:sizeof(CFUUIDBytes)];
+ return [d autorelease];
+}
+
+- (CFUUIDBytes) UUIDBytes {
+ return CFUUIDGetUUIDBytes(uuid);
+}
+
+- (BOOL) isEqual:(id) o {
+ BOOL isOK = [o isKindOfClass:[self class]] &&
+ CFEqual([o CFUUID], [self CFUUID]);
+// NSLog(@"Will test for equality: self %@ with %@ result %d", self, o, isOK);
+ return isOK;
+}
+
+- (NSUInteger) hash {
+ return [[self class] hash] ^ CFHash(uuid);
+}
+
+- (void) dealloc {
+ CFRelease(uuid);
+ [super dealloc];
+}
+
++ (id) UUID {
+ return [[[self alloc] init] autorelease];
+}
+
++ (id) UUIDWithUUID:(CFUUIDRef) uuid {
+ return [[[self alloc] initWithUUID:uuid] autorelease];
+}
+
++ (id) UUIDWithString:(NSString*) string {
+ return [[[self alloc] initWithString:string] autorelease];
+}
+
++ (id) UUIDWithBytes:(CFUUIDBytes*) bytes {
+ return [[[self alloc] initWithBytes:bytes] autorelease];
+}
+
++ (id) UUIDWithData:(NSData*) data {
+ return [[[self alloc] initWithData:data] autorelease];
+}
+
+- (id) copyWithZone:(NSZone*) zone {
+ return [[[self class] allocWithZone:zone] initWithUUID:[self CFUUID]];
+}
+
+- (id) copy {
+ return [self retain];
+}
+
+- (void) encodeWithCoder:(NSCoder*) c {
+ [c encodeObject:self.dataValue forKey:@"UUIDData"];
+}
+
+- (id) initWithCoder:(NSCoder*) c {
+ NSData* d = [c decodeObjectForKey:@"UUIDData"];
+ return [self initWithData:d];
+}
+
+@end
View
@@ -0,0 +1,13 @@
+#ifndef __OBJC__
+#error MuiKit requires Objective-C
+#endif
+
+#import <UIKit/UIKit.h>
+
+#import "L0ExternalURLOpeningDetection.h"
+#import "L0SolicitReviewController.h"
+#import "UIImage_L0RenderingAdditions.h"
+#import "L0DraggableView.h"
+#import "UIAlertView+L0Alert.h"
+#import "L0UUID.h"
+
Oops, something went wrong.

0 comments on commit 9f8e363

Please sign in to comment.