Permalink
Browse files

ARC support

  • Loading branch information...
1 parent 62e9af6 commit eb7ce42efbcbcc79abe46e554fb8ff26d3a12fc1 @keeshux committed Oct 20, 2012
Showing with 123 additions and 47 deletions.
  1. +59 −0 ARCHelper.h
  2. +1 −0 Categories/NSString+DateConversion/NSString+DateConversion.h
  3. +1 −0 Categories/NSString+Random/NSString+Random.h
  4. +2 −2 Categories/NSString+Random/NSString+Random.m
  5. +4 −4 Categories/NSTimer+Pause/NSTimer+Pause.m
  6. +1 −0 Categories/UIBarButtonItem+CustomImage/UIBarButtonItem+CustomImage.h
  7. +2 −0 Categories/UIViewController+SubtitleView/UIViewController+SubtitleView.h
  8. +1 −0 Categories/UIWebView+Activity/UIWebView+Activity.h
  9. +1 −0 Classes/KSBasicMapAnnotation/KSBasicMapAnnotation.h
  10. +1 −1 Classes/KSBasicMapAnnotation/KSBasicMapAnnotation.m
  11. +3 −2 Classes/KSCheckView/KSCheckView.h
  12. +1 −1 Classes/KSCheckView/KSCheckView.m
  13. +1 −0 Classes/KSEditEnder/KSEditEnder.h
  14. +2 −1 Classes/KSSheetView/KSSheetView.h
  15. +1 −1 Classes/KSSheetView/KSSheetView.m
  16. +6 −2 Demo/ComponentsDemo.xcodeproj/project.pbxproj
  17. +1 −1 Demo/ComponentsDemo/AppDelegate.m
  18. +1 −0 Demo/ComponentsDemo/ComponentsDemo-Prefix.pch
  19. +4 −4 Demo/ComponentsDemo/Tests/Categories/NSMutableArray+Shuffling/VC_NSMutableArray_Shuffling.h
  20. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSMutableArray+Shuffling/VC_NSMutableArray_Shuffling.m
  21. +5 −5 Demo/ComponentsDemo/Tests/Categories/NSString+DateConversion/VC_NSString_DateConversion.h
  22. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSString+DateConversion/VC_NSString_DateConversion.m
  23. +3 −3 Demo/ComponentsDemo/Tests/Categories/NSString+Digest/VC_NSString_Digest.h
  24. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSString+Digest/VC_NSString_Digest.m
  25. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSString+Random/VC_NSString_Random.h
  26. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSString+Random/VC_NSString_Random.m
  27. +2 −2 Demo/ComponentsDemo/Tests/Categories/NSTimer+Pause/VC_NSTimer_Pause.h
  28. +1 −1 Demo/ComponentsDemo/Tests/Categories/NSTimer+Pause/VC_NSTimer_Pause.m
  29. +2 −2 Demo/ComponentsDemo/Tests/Categories/UIAcceleration+DeviceAngle/VC_UIAcceleration_DeviceAngle.h
  30. +1 −1 Demo/ComponentsDemo/Tests/Categories/UIAcceleration+DeviceAngle/VC_UIAcceleration_DeviceAngle.m
  31. +2 −2 Demo/ComponentsDemo/Tests/Classes/KSEditEnder/VC_KSEditEnder.h
  32. +1 −1 Demo/ComponentsDemo/Tests/Classes/KSEditEnder/VC_KSEditEnder.m
  33. +1 −1 Demo/ComponentsDemo/ViewController.h
  34. +3 −5 Demo/ComponentsDemo/ViewController.m
  35. +4 −0 README.md
View
@@ -0,0 +1,59 @@
+//
+// ARC Helper
+//
+// Version 2.1
+//
+// Created by Nick Lockwood on 05/01/2012.
+// Copyright 2012 Charcoal Design
+//
+// Distributed under the permissive zlib license
+// Get the latest version from here:
+//
+// https://gist.github.com/1563325
+//
+
+#ifndef ah_retain
+#if __has_feature(objc_arc)
+#define ah_retain self
+#define ah_dealloc self
+#define release self
+#define autorelease self
+#else
+#define ah_retain retain
+#define ah_dealloc dealloc
+#define __bridge
+#endif
+#endif
+
+// Weak reference support
+
+#import <Availability.h>
+#if (!__has_feature(objc_arc)) || \
+(defined __IPHONE_OS_VERSION_MIN_REQUIRED && \
+__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0) || \
+(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \
+__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7)
+#undef weak
+#define weak unsafe_unretained
+#undef __weak
+#define __weak __unsafe_unretained
+#endif
+
+// Weak delegate support
+
+#ifndef ah_weak
+#import <Availability.h>
+#if (__has_feature(objc_arc)) && \
+((defined __IPHONE_OS_VERSION_MIN_REQUIRED && \
+__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0) || \
+(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \
+__MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_7))
+#define ah_weak weak
+#define __ah_weak __weak
+#else
+#define ah_weak unsafe_unretained
+#define __ah_weak __unsafe_unretained
+#endif
+#endif
+
+// ARC Helper ends
@@ -18,6 +18,7 @@
*/
#import <Foundation/Foundation.h>
+#import "ARCHelper.h"
@interface NSString (DateConversion)
@@ -18,6 +18,7 @@
*/
#import <Foundation/Foundation.h>
+#import "ARCHelper.h"
@interface NSString (Random)
@@ -25,13 +25,13 @@ @implementation NSString (Random)
+ (id) randomStringWithLength:(NSUInteger)length
{
- NSMutableString *randomString = [NSMutableString stringWithCapacity:length];
+ NSMutableString *randomString = [[NSMutableString alloc] initWithCapacity:length];
for (NSUInteger i = 0; i < length; ++i) {
[randomString appendFormat:@"%c", [letters characterAtIndex:(arc4random() % [letters length])]];
}
- return randomString;
+ return [randomString autorelease];
}
@end
@@ -27,16 +27,16 @@ @implementation NSTimer (Pause)
- (void) pause
{
- objc_setAssociatedObject(self, NSTimerPauseDate, [NSDate date], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- objc_setAssociatedObject(self, NSTimerPreviousFireDate, self.fireDate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(self, (__bridge const void *)(NSTimerPauseDate), [NSDate date], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(self, (__bridge const void *)(NSTimerPreviousFireDate), self.fireDate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.fireDate = [NSDate distantFuture];
}
- (void) resume
{
- NSDate *pauseDate = objc_getAssociatedObject(self, NSTimerPauseDate);
- NSDate *previousFireDate = objc_getAssociatedObject(self, NSTimerPreviousFireDate);
+ NSDate *pauseDate = objc_getAssociatedObject(self, (__bridge const void *)NSTimerPauseDate);
+ NSDate *previousFireDate = objc_getAssociatedObject(self, (__bridge const void *)NSTimerPreviousFireDate);
const NSTimeInterval pauseTime = -[pauseDate timeIntervalSinceNow];
self.fireDate = [NSDate dateWithTimeInterval:pauseTime sinceDate:previousFireDate];
@@ -18,6 +18,7 @@
*/
#import <Foundation/Foundation.h>
+#import "ARCHelper.h"
// NOTE: customView is an UIButton
@@ -17,6 +17,8 @@
*
*/
+#import "ARCHelper.h"
+
@interface UIViewController (SubtitleView)
- (void) setTitle:(NSString *)title subtitle:(NSString *)subtitle;
@@ -18,6 +18,7 @@
*/
#import <UIKit/UIKit.h>
+#import "ARCHelper.h"
@interface UIWebView (Activity)
@@ -20,6 +20,7 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
+#import "ARCHelper.h"
@interface KSBasicMapAnnotation : NSObject<MKAnnotation>
@@ -45,7 +45,7 @@ - (void) dealloc
self.title = nil;
self.subtitle = nil;
- [super dealloc];
+ [super ah_dealloc];
}
@end
@@ -18,6 +18,7 @@
*/
#import <UIKit/UIKit.h>
+#import "ARCHelper.h"
@protocol KSCheckViewDelegate;
@@ -27,9 +28,9 @@
}
@property (nonatomic, assign) BOOL checked;
-@property (nonatomic, retain) UIColor *color;
+@property (nonatomic, strong) UIColor *color;
-@property (nonatomic, assign) id<KSCheckViewDelegate> delegate;
+@property (nonatomic, ah_weak) id<KSCheckViewDelegate> delegate;
- (void) toggleChecked;
@@ -50,7 +50,7 @@ - (void) dealloc
CGPathRelease(path);
self.color = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void) setChecked:(BOOL)aChecked
@@ -18,6 +18,7 @@
*/
#import <Foundation/Foundation.h>
+#import "ARCHelper.h"
@interface KSEditEnder : UIControl
@@ -18,6 +18,7 @@
*/
#import <UIKit/UIKit.h>
+#import "ARCHelper.h"
@protocol KSSheetViewDelegate;
@@ -35,7 +36,7 @@
@property (nonatomic, readonly) NSUInteger gridHeight;
// for custom drawing
-@property (nonatomic, assign) id<KSSheetViewDelegate> delegate;
+@property (nonatomic, ah_weak) id<KSSheetViewDelegate> delegate;
@end
@@ -58,7 +58,7 @@ - (void) dealloc
CGColorRelease(paperColor);
CGColorRelease(lineColor);
- [super dealloc];
+ [super ah_dealloc];
}
- (void) setCellSize:(NSUInteger)aCellSize
@@ -115,6 +115,7 @@
8CB228171591455400965996 /* UIColor+Darkening.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Darkening.m"; sourceTree = "<group>"; };
8CB2282815914BC400965996 /* VC_UIViewController_SubtitleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VC_UIViewController_SubtitleView.h; sourceTree = "<group>"; };
8CB2282915914BC400965996 /* VC_UIViewController_SubtitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VC_UIViewController_SubtitleView.m; sourceTree = "<group>"; };
+ 8CC7F7401633411300A6511F /* ARCHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARCHelper.h; path = ../../ARCHelper.h; sourceTree = "<group>"; };
8CCC9723151FE1870085C7EE /* NSString+Random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Random.h"; sourceTree = "<group>"; };
8CCC9724151FE1870085C7EE /* NSString+Random.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Random.m"; sourceTree = "<group>"; };
8CCC9728151FE1ED0085C7EE /* VC_NSString_Random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VC_NSString_Random.h; sourceTree = "<group>"; };
@@ -212,6 +213,7 @@
8C4D3D06146754690093F771 /* Tests */,
8C2C55B0146750E70065A877 /* AppDelegate.h */,
8C2C55B1146750E70065A877 /* AppDelegate.m */,
+ 8CC7F7401633411300A6511F /* ARCHelper.h */,
8C4D3D081467549D0093F771 /* ViewController.h */,
8C4D3D091467549D0093F771 /* ViewController.m */,
8C4D3D0E146756170093F771 /* ViewController_iPhone.xib */,
@@ -716,6 +718,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = NO;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -730,7 +733,7 @@
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 3.2;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PROVISIONING_PROFILE = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
@@ -742,14 +745,15 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = NO;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 3.2;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PROVISIONING_PROFILE = "";
SDKROOT = iphoneos;
@@ -16,7 +16,7 @@ @implementation AppDelegate
- (void)dealloc
{
[_window release];
- [super dealloc];
+ [super ah_dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -11,4 +11,5 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
+ #import "ARCHelper.h"
#endif
@@ -10,10 +10,10 @@
@interface VC_NSMutableArray_Shuffling : UIViewController
-@property (nonatomic, retain) NSMutableArray *testData;
-@property (nonatomic, retain) UILabel *beforeLabel;
-@property (nonatomic, retain) UIButton *shuffleButton;
-@property (nonatomic, retain) UILabel *afterLabel;
+@property (nonatomic, strong) NSMutableArray *testData;
+@property (nonatomic, strong) UILabel *beforeLabel;
+@property (nonatomic, strong) UIButton *shuffleButton;
+@property (nonatomic, strong) UILabel *afterLabel;
- (void) shuffleData:(id)sender;
@@ -32,7 +32,7 @@ - (void) dealloc
self.shuffleButton = nil;
self.afterLabel = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void)didReceiveMemoryWarning
@@ -10,11 +10,11 @@
@interface VC_NSString_DateConversion : UIViewController <UITextFieldDelegate>
-@property (nonatomic, retain) UITextField *inputDate;
-@property (nonatomic, retain) UITextField *inputFormat;
-@property (nonatomic, retain) UITextField *outputFormat;
-@property (nonatomic, retain) UILabel *outputDate;
-@property (nonatomic, retain) UIButton *convertButton;
+@property (nonatomic, strong) UITextField *inputDate;
+@property (nonatomic, strong) UITextField *inputFormat;
+@property (nonatomic, strong) UITextField *outputFormat;
+@property (nonatomic, strong) UILabel *outputDate;
+@property (nonatomic, strong) UIButton *convertButton;
- (void) convertDate:(id)sender;
@@ -25,7 +25,7 @@ - (void) dealloc
self.outputDate = nil;
self.convertButton = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void)didReceiveMemoryWarning
@@ -10,9 +10,9 @@
@interface VC_NSString_Digest : UIViewController
-@property (nonatomic, retain) UITextField *inputField;
-@property (nonatomic, retain) UITextField *outputField;
-@property (nonatomic, retain) UISegmentedControl *digestChoice;
+@property (nonatomic, strong) UITextField *inputField;
+@property (nonatomic, strong) UITextField *outputField;
+@property (nonatomic, strong) UISegmentedControl *digestChoice;
- (void) updateDigest;
@@ -30,7 +30,7 @@ - (void) dealloc
self.outputField = nil;
self.digestChoice = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void)didReceiveMemoryWarning
@@ -10,7 +10,7 @@
@interface VC_NSString_Random : UIViewController
-@property (nonatomic, retain) UITextField *outputField;
+@property (nonatomic, strong) UITextField *outputField;
- (void) generateString;
@@ -30,7 +30,7 @@ - (void) dealloc
{
self.outputField = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void)viewDidLoad
@@ -12,7 +12,7 @@
NSUInteger seconds;
}
-@property (nonatomic, retain) UILabel *countdownLabel;
-@property (nonatomic, retain) NSTimer *timer;
+@property (nonatomic, strong) UILabel *countdownLabel;
+@property (nonatomic, strong) NSTimer *timer;
@end
@@ -28,7 +28,7 @@ - (void) dealloc
self.countdownLabel = nil;
self.timer = nil;
- [super dealloc];
+ [super ah_dealloc];
}
- (void)didReceiveMemoryWarning
Oops, something went wrong.

0 comments on commit eb7ce42

Please sign in to comment.