Skip to content

Commit

Permalink
Conditionally support ARC, use ARC for demo project (issue domesticca…
Browse files Browse the repository at this point in the history
  • Loading branch information
ringw committed Nov 14, 2012
1 parent 2c75c8b commit d66b029
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
46 changes: 38 additions & 8 deletions DCRoundSwitch/DCRoundSwitch.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@

@interface DCRoundSwitch () <UIGestureRecognizerDelegate>

#if __has_feature(objc_arc)
@property (nonatomic, strong) DCRoundSwitchOutlineLayer *outlineLayer;
@property (nonatomic, strong) DCRoundSwitchToggleLayer *toggleLayer;
@property (nonatomic, strong) DCRoundSwitchKnobLayer *knobLayer;
@property (nonatomic, strong) CAShapeLayer *clipLayer;
@property (nonatomic) BOOL ignoreTap;
#else
@property (nonatomic, retain) DCRoundSwitchOutlineLayer *outlineLayer;
@property (nonatomic, retain) DCRoundSwitchToggleLayer *toggleLayer;
@property (nonatomic, retain) DCRoundSwitchKnobLayer *knobLayer;
@property (nonatomic, retain) CAShapeLayer *clipLayer;
@property (nonatomic, assign) BOOL ignoreTap;
#endif

- (void)setup;
- (void)useLayerMasking;
Expand All @@ -37,7 +45,8 @@ @implementation DCRoundSwitch
#pragma mark -
#pragma mark Init & Memory Managment

/*- (void)dealloc
#if !__has_feature(objc_arc)
- (void)dealloc
{
[outlineLayer release];
[toggleLayer release];
Expand All @@ -49,7 +58,8 @@ @implementation DCRoundSwitch
[offText release];

[super dealloc];
}*/
}
#endif

- (id)init
{
Expand Down Expand Up @@ -130,6 +140,9 @@ - (void)setup
// toggleLayer so it doesn't bleed out over the outlineLayer.

self.toggleLayer = [[[[self class] toggleLayerClass] alloc] initWithOnString:self.onText offString:self.offText onTintColor:[UIColor colorWithRed:0.000 green:0.478 blue:0.882 alpha:1.0]];
#if !__has_feature(objc_arc)
[self.toggleLayer autorelease];
#endif
self.toggleLayer.drawOnTint = NO;
self.toggleLayer.clip = YES;
[self.layer addSublayer:self.toggleLayer];
Expand All @@ -156,6 +169,11 @@ - (void)setup
action:@selector(toggleDragged:)];
[panGestureRecognizer setDelegate:self];
[self addGestureRecognizer:panGestureRecognizer];

#if !__has_feature(objc_arc)
[tapGestureRecognizer autorelease];
[panGestureRecognizer autorelease];
#endif

[self setNeedsLayout];

Expand Down Expand Up @@ -352,8 +370,10 @@ - (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)igno
[self useLayerMasking];
[self positionLayersAndMask];

#if !__has_feature(objc_arc)
// retain all our targets so they don't disappear before the actions get sent at the end of the animation
//[[self allTargets] makeObjectsPerformSelector:@selector(retain)];
[[self allTargets] makeObjectsPerformSelector:@selector(retain)];
#endif

[CATransaction setCompletionBlock:^{
[CATransaction begin];
Expand Down Expand Up @@ -399,7 +419,9 @@ - (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)igno
if (previousOn != on && !ignoreControlEvents)
[self sendActionsForControlEvents:UIControlEventValueChanged];

//[[self allTargets] makeObjectsPerformSelector:@selector(release)];
#if !__has_feature(objc_arc)
[[self allTargets] makeObjectsPerformSelector:@selector(release)];
#endif
}];

[CATransaction commit];
Expand All @@ -410,8 +432,12 @@ - (void)setOnTintColor:(UIColor *)anOnTintColor
{
if (anOnTintColor != onTintColor)
{
//[onTintColor release];
onTintColor = [anOnTintColor copy];
#if __has_feature(objc_arc)
onTintColor = anOnTintColor;
#else
[onTintColor release];
onTintColor = [anOnTintColor retain];
#endif
self.toggleLayer.onTintColor = anOnTintColor;
[self.toggleLayer setNeedsDisplay];
}
Expand Down Expand Up @@ -447,7 +473,9 @@ - (void)setOnText:(NSString *)newOnText
{
if (newOnText != onText)
{
//[onText release];
#if !__has_feature(objc_arc)
[onText release];
#endif
onText = [newOnText copy];
self.toggleLayer.onString = onText;
[self.toggleLayer setNeedsDisplay];
Expand All @@ -458,7 +486,9 @@ - (void)setOffText:(NSString *)newOffText
{
if (newOffText != offText)
{
//[offText release];
#if !__has_feature(objc_arc)
[offText release];
#endif
offText = [newOffText copy];
self.toggleLayer.offString = offText;
[self.toggleLayer setNeedsDisplay];
Expand Down
7 changes: 7 additions & 0 deletions DCRoundSwitch/DCRoundSwitchToggleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@

@interface DCRoundSwitchToggleLayer : CALayer

#if __has_feature(objc_arc)
@property (nonatomic, strong) UIColor *onTintColor;
@property (nonatomic, strong) NSString *onString;
@property (nonatomic, strong) NSString *offString;
@property (nonatomic, readonly) UIFont *labelFont;
#else
@property (nonatomic, retain) UIColor *onTintColor;
@property (nonatomic, retain) NSString *onString;
@property (nonatomic, retain) NSString *offString;
@property (nonatomic, readonly) UIFont *labelFont;
#endif
@property (nonatomic) BOOL drawOnTint;
@property (nonatomic) BOOL clip;

Expand Down
6 changes: 4 additions & 2 deletions DCRoundSwitch/DCRoundSwitchToggleLayer.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ @implementation DCRoundSwitchToggleLayer
@synthesize clip;
@synthesize labelFont;

/*- (void)dealloc
#if !__has_feature(objc_arc)
- (void)dealloc
{
[onString release];
[offString release];
[onTintColor release];

[super dealloc];
}*/
}
#endif

- (id)initWithOnString:(NSString *)anOnString offString:(NSString *)anOffString onTintColor:(UIColor *)anOnTintColor
{
Expand Down
2 changes: 2 additions & 0 deletions DCRoundSwitchDemo/DCRoundSwitchDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -288,6 +289,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DCRoundSwitchDemo/DCRoundSwitchDemo-Prefix.pch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
@implementation DCRoundSwitchDemoAppDelegate
@synthesize window, viewController;

- (void)dealloc
{
[window release];
[viewController release];

[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ @implementation DCRoundSwitchDemoViewController
@synthesize switch3;
@synthesize longSwitch;

- (void)dealloc
{
[longSwitch release];
[fatSwitch release];
[switch1 release];
[switch2 release];
[switch3 release];

[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
Expand Down
2 changes: 0 additions & 2 deletions DCRoundSwitchDemo/DCRoundSwitchDemo/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}

0 comments on commit d66b029

Please sign in to comment.