diff --git a/DCIntrospect/ARCMacros.h b/DCIntrospect/ARCMacros.h new file mode 100644 index 0000000..9b6f318 --- /dev/null +++ b/DCIntrospect/ARCMacros.h @@ -0,0 +1,60 @@ +// +// ARCMacros.h +// +// Created by John Blanco on 1/28/2011. +// Rapture In Venice releases all rights to this code. Feel free use and/or copy it openly and freely! +// + +#if !defined(__clang__) || __clang_major__ < 3 + #ifndef __bridge + #define __bridge + #endif + + #ifndef __bridge_retain + #define __bridge_retain + #endif + + #ifndef __bridge_retained + #define __bridge_retained + #endif + + #ifndef __autoreleasing + #define __autoreleasing + #endif + + #ifndef __strong + #define __strong + #endif + + #ifndef __unsafe_unretained + #define __unsafe_unretained + #endif + + #ifndef __weak + #define __weak + #endif +#endif + +#if __has_feature(objc_arc) + #define SAFE_ARC_PROP_RETAIN strong + #define SAFE_ARC_RETAIN(x) (x) + #define SAFE_ARC_RELEASE(x) + #define SAFE_ARC_AUTORELEASE(x) (x) + #define SAFE_ARC_BLOCK_COPY(x) (x) + #define SAFE_ARC_BLOCK_RELEASE(x) + #define SAFE_ARC_SUPER_DEALLOC() + #define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool { + #define SAFE_ARC_AUTORELEASE_POOL_END() } + #define SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END() } +#else + #define SAFE_ARC_PROP_RETAIN retain + #define SAFE_ARC_RETAIN(x) ([(x) retain]) + #define SAFE_ARC_RELEASE(x) ([(x) release]) + #define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease]) + #define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x)) + #define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x)) + #define SAFE_ARC_SUPER_DEALLOC() ([super dealloc]) + #define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + #define SAFE_ARC_AUTORELEASE_POOL_END() [pool release]; + #define SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END() [pool drain]; +#endif diff --git a/DCIntrospect/DCCrossHairView.m b/DCIntrospect/DCCrossHairView.m index cc1c989..ae50afd 100644 --- a/DCIntrospect/DCCrossHairView.m +++ b/DCIntrospect/DCCrossHairView.m @@ -9,11 +9,13 @@ @implementation DCCrossHairView @synthesize color; +#if !__has_feature(objc_arc) - (void)dealloc { [color release]; [super dealloc]; } +#endif - (id)initWithFrame:(CGRect)frame color:(UIColor *)aColor { diff --git a/DCIntrospect/DCFrameView.m b/DCIntrospect/DCFrameView.m index 040fcd9..b4b0b7f 100644 --- a/DCIntrospect/DCFrameView.m +++ b/DCIntrospect/DCFrameView.m @@ -5,6 +5,7 @@ // #import "DCFrameView.h" +#import "ARCMacros.h" @implementation DCFrameView @synthesize delegate; @@ -13,6 +14,7 @@ @implementation DCFrameView @synthesize rectsToOutline; @synthesize touchPointView; +#if !__has_feature(objc_arc) - (void)dealloc { self.delegate = nil; @@ -21,6 +23,7 @@ - (void)dealloc [super dealloc]; } +#endif #pragma mark - Setup @@ -33,7 +36,7 @@ - (id)initWithFrame:(CGRect)frame delegate:(id)aDelegate self.backgroundColor = [UIColor clearColor]; self.opaque = NO; - self.touchPointLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; + self.touchPointLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectZero]); self.touchPointLabel.text = @"X 320 Y 480"; self.touchPointLabel.font = [UIFont boldSystemFontOfSize:12.0f]; self.touchPointLabel.textAlignment = UITextAlignmentCenter; @@ -46,7 +49,7 @@ - (id)initWithFrame:(CGRect)frame delegate:(id)aDelegate self.rectsToOutline = [NSMutableArray array]; - self.touchPointView = [[[DCCrossHairView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 17.0f, 17.0f) color:[UIColor blueColor]] autorelease]; + self.touchPointView = SAFE_ARC_AUTORELEASE([[DCCrossHairView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 17.0f, 17.0f) color:[UIColor blueColor]]); self.touchPointView.alpha = 0.0f; [self addSubview:self.touchPointView]; } diff --git a/DCIntrospect/DCIntrospect.m b/DCIntrospect/DCIntrospect.m index cc4b4cf..11cc182 100644 --- a/DCIntrospect/DCIntrospect.m +++ b/DCIntrospect/DCIntrospect.m @@ -5,6 +5,7 @@ // #import "DCIntrospect.h" +#import "ARCMacros.h" #import #include @@ -82,7 +83,7 @@ @implementation DCIntrospect + (void)load { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SAFE_ARC_AUTORELEASE_POOL_START(); NSString *simulatorRoot = [[[NSProcessInfo processInfo] environment] objectForKey:@"IPHONE_SIMULATOR_ROOT"]; if (simulatorRoot) @@ -101,12 +102,12 @@ + (void)load } } - [pool drain]; + SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END(); } static void *originalValueForKeyIMPKey = &originalValueForKeyIMPKey; -id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key); +//id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key); id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key) { static NSMutableSet *textInputTraitsProperties = nil; @@ -186,16 +187,16 @@ - (void)start if (!self.statusBarOverlay) { - self.statusBarOverlay = [[[DCStatusBarOverlay alloc] init] autorelease]; + self.statusBarOverlay = SAFE_ARC_AUTORELEASE([[DCStatusBarOverlay alloc] init]); } if (!self.inputTextView) { - self.inputTextView = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease]; + self.inputTextView = SAFE_ARC_AUTORELEASE([[UITextView alloc] initWithFrame:CGRectZero]); self.inputTextView.delegate = self; self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo; self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone; - self.inputTextView.inputView = [[[UIView alloc] init] autorelease]; + self.inputTextView.inputView = SAFE_ARC_AUTORELEASE([[UIView alloc] init]); self.inputTextView.scrollsToTop = NO; [mainWindow addSubview:self.inputTextView]; } @@ -236,7 +237,7 @@ - (void)start [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateViews) name:UIDeviceOrientationDidChangeNotification object:nil]; if (!self.currentViewHistory) - self.currentViewHistory = [[[NSMutableArray alloc] init] autorelease]; + self.currentViewHistory = SAFE_ARC_AUTORELEASE([[NSMutableArray alloc] init]); NSLog(@"DCIntrospect is setup. %@ to start.", [kDCIntrospectKeysInvoke isEqualToString:@" "] ? @"Push the space bar" : [NSString stringWithFormat:@"Type '%@'", kDCIntrospectKeysInvoke]); } @@ -261,9 +262,9 @@ - (void)setInvokeGestureRecognizer:(UIGestureRecognizer *)newGestureRecognizer UIWindow *mainWindow = [self mainWindow]; [mainWindow removeGestureRecognizer:invokeGestureRecognizer]; - [invokeGestureRecognizer release]; + SAFE_ARC_RELEASE(invokeGestureRecognizer); invokeGestureRecognizer = nil; - invokeGestureRecognizer = [newGestureRecognizer retain]; + invokeGestureRecognizer = SAFE_ARC_RETAIN(newGestureRecognizer); [invokeGestureRecognizer addTarget:self action:@selector(invokeIntrospector)]; [mainWindow addGestureRecognizer:invokeGestureRecognizer]; } @@ -730,7 +731,8 @@ - (void)updateFrameView UIWindow *mainWindow = [self mainWindow]; if (!self.frameView) { - self.frameView = [[[DCFrameView alloc] initWithFrame:(CGRect){ CGPointZero, mainWindow.frame.size } delegate:self] autorelease]; + CGRect frame = (CGRect){ CGPointZero, mainWindow.frame.size }; + self.frameView = SAFE_ARC_AUTORELEASE([[DCFrameView alloc] initWithFrame:frame delegate:self]); [mainWindow addSubview:self.frameView]; self.frameView.alpha = 0.0f; [self updateViews]; @@ -1294,13 +1296,13 @@ - (void)toggleHelp { self.statusBarOverlay.leftLabel.text = @"Help"; self.statusBarOverlay.rightLabel.text = @"Any key to close"; - UIView *backingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.frame.size.width, mainWindow.frame.size.height)] autorelease]; + UIView *backingView = SAFE_ARC_AUTORELEASE([[UIView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.frame.size.width, mainWindow.frame.size.height)]); backingView.tag = 1548; backingView.alpha = 0; backingView.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.85f]; [mainWindow addSubview:backingView]; - UIWebView *webView = [[[UIWebView alloc] initWithFrame:backingView.frame] autorelease]; + UIWebView *webView = SAFE_ARC_AUTORELEASE([[UIWebView alloc] initWithFrame:backingView.frame]); webView.opaque = NO; webView.backgroundColor = [UIColor clearColor]; webView.delegate = self; @@ -1560,7 +1562,7 @@ - (NSArray *)subclassesOfClass:(Class)parentClass int numClasses = objc_getClassList(NULL, 0); Class *classes = NULL; - classes = malloc(sizeof(Class) * numClasses); + classes = (Class *)malloc(sizeof(Class) * numClasses); numClasses = objc_getClassList(classes, numClasses); NSMutableArray *result = [NSMutableArray array]; @@ -1616,7 +1618,7 @@ - (NSMutableArray *)viewsAtPoint:(CGPoint)touchPoint inView:(UIView *)view } } - return [views autorelease]; + return SAFE_ARC_AUTORELEASE(views); } - (void)fadeView:(UIView *)view toAlpha:(CGFloat)alpha diff --git a/DCIntrospect/DCStatusBarOverlay.m b/DCIntrospect/DCStatusBarOverlay.m index 7be771e..a590b08 100644 --- a/DCIntrospect/DCStatusBarOverlay.m +++ b/DCIntrospect/DCStatusBarOverlay.m @@ -5,10 +5,12 @@ // #import "DCStatusBarOverlay.h" +#import "ARCMacros.h" @implementation DCStatusBarOverlay @synthesize leftLabel, rightLabel; +#if !__has_feature(objc_arc) - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; @@ -18,6 +20,7 @@ - (void)dealloc [super dealloc]; } +#endif #pragma mark Setup @@ -39,9 +42,9 @@ - (id)init UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame]; backgroundImageView.image = [[UIImage imageNamed:@"statusBarBackground.png"] stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f]; [self addSubview:backgroundImageView]; - [backgroundImageView release]; + SAFE_ARC_RELEASE(backgroundImageView); - self.leftLabel = [[[UILabel alloc] initWithFrame:CGRectOffset(self.frame, 2.0f, 0.0f)] autorelease]; + self.leftLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectOffset(self.frame, 2.0f, 0.0f)]); self.leftLabel.backgroundColor = [UIColor clearColor]; self.leftLabel.textAlignment = UITextAlignmentLeft; self.leftLabel.font = [UIFont boldSystemFontOfSize:12.0f]; @@ -49,7 +52,7 @@ - (id)init self.leftLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; [self addSubview:self.leftLabel]; - self.rightLabel = [[[UILabel alloc] initWithFrame:CGRectOffset(self.frame, -2.0f, 0.0f)] autorelease]; + self.rightLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectOffset(self.frame, -2.0f, 0.0f)]); self.rightLabel.backgroundColor = [UIColor clearColor]; self.rightLabel.font = [UIFont boldSystemFontOfSize:12.0f]; self.rightLabel.textAlignment = UITextAlignmentRight; @@ -57,7 +60,7 @@ - (id)init self.rightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; [self addSubview:self.rightLabel]; - UITapGestureRecognizer *gestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)] autorelease]; + UITapGestureRecognizer *gestureRecognizer = SAFE_ARC_AUTORELEASE([[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)]); [self addGestureRecognizer:gestureRecognizer]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];