Skip to content

Commit

Permalink
Convert to ARC!
Browse files Browse the repository at this point in the history
A "pre-ARC" tag has been added, if you want
the non-ARC version. But it will not receive
any future development.
  • Loading branch information
bjhomer committed May 5, 2012
1 parent e413079 commit 04ccc9f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 49 deletions.
4 changes: 2 additions & 2 deletions HSImageSidebarView/HSImageSidebarView.h
Expand Up @@ -14,9 +14,9 @@
}

@property (readonly) NSUInteger imageCount;
@property (readonly) NSIndexSet *visibleIndices;
@property (strong, readonly) NSIndexSet *visibleIndices;

@property (assign) id<HSImageSidebarViewDelegate> delegate;
@property (weak) id<HSImageSidebarViewDelegate> delegate;
@property (assign) CGFloat rowHeight;
@property (assign) NSInteger selectedIndex;

Expand Down
34 changes: 12 additions & 22 deletions HSImageSidebarView/HSImageSidebarView.m
Expand Up @@ -12,20 +12,20 @@

@interface HSImageSidebarView () <UIScrollViewDelegate>

@property (retain) UIScrollView *scrollView;
@property (retain) CAGradientLayer *selectionGradient;
@property (strong) UIScrollView *scrollView;
@property (strong) CAGradientLayer *selectionGradient;

@property (retain) NSMutableArray *imageViews;
@property (retain) NSMutableArray *viewsForReuse;
@property (retain) NSMutableIndexSet *indexesToAnimate;
@property (strong) NSMutableArray *imageViews;
@property (strong) NSMutableArray *viewsForReuse;
@property (strong) NSMutableIndexSet *indexesToAnimate;
@property (assign) BOOL shouldAnimateSelectionLayer;

@property (assign) BOOL initialized;
@property (assign) BOOL isHorizontal;

@property (retain) NSTimer *dragScrollTimer;
@property (strong) NSTimer *dragScrollTimer;

@property (retain) UIView *viewBeingDragged;
@property (strong) UIView *viewBeingDragged;
@property (assign) NSInteger draggedViewOldIndex;
@property (assign) CGPoint dragOffset;

Expand Down Expand Up @@ -79,23 +79,15 @@ - (id)initWithCoder:(NSCoder *)aDecoder {


- (void)dealloc {
[_scrollView release];
[imageViews release];
[viewsForReuse release];
[indexesToAnimate release];
[viewBeingDragged release];
[selectionGradient release];
[dragScrollTimer invalidate];
[dragScrollTimer release];
[super dealloc];
}

#pragma mark -
#pragma mark Setup

- (void) setupViewHierarchy {

self.scrollView = [[[UIScrollView alloc] initWithFrame:self.bounds] autorelease];
self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
_scrollView.delegate = self;
if (self.bounds.size.width > self.bounds.size.height) {
isHorizontal = YES;
Expand Down Expand Up @@ -128,11 +120,9 @@ - (void) setupViewHierarchy {

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedSidebar:)];
[self addGestureRecognizer:tapRecognizer];
[tapRecognizer release];

UILongPressGestureRecognizer *pressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pressedSidebar:)];
[self addGestureRecognizer:pressRecognizer];
[pressRecognizer release];
}

- (void) setupInstanceVariables {
Expand Down Expand Up @@ -178,7 +168,7 @@ - (void)layoutSubviews {

UIImageView *imageView = [self dequeueReusableImageView];
if (imageView == nil) {
imageView = [[[UIImageView alloc] init] autorelease];
imageView = [[UIImageView alloc] init];
}
imageView.image = image;

Expand Down Expand Up @@ -221,7 +211,7 @@ - (void)layoutSubviews {
if (selectedIndex >= 0) {
CFBooleanRef disableAnimations = shouldAnimateSelectionLayer ? kCFBooleanFalse : kCFBooleanTrue;
[CATransaction begin];
[CATransaction setValue:(id)disableAnimations
[CATransaction setValue:(__bridge id)disableAnimations
forKey:kCATransactionDisableActions];

selectionGradient.hidden = NO;
Expand Down Expand Up @@ -637,11 +627,11 @@ - (void)enqueueReusableImageView:(UIImageView *)view {
}

- (UIImageView *)dequeueReusableImageView {
UIImageView *view = [[viewsForReuse lastObject] retain];
UIImageView *view = [viewsForReuse lastObject];
if (view != nil) {
[viewsForReuse removeLastObject];
}
return [view autorelease];
return view;
}

- (CGRect)frameOfImageAtIndex:(NSUInteger)anIndex {
Expand Down
4 changes: 4 additions & 0 deletions Sidebar.xcodeproj/project.pbxproj
Expand Up @@ -310,11 +310,13 @@
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;
GCC_PREFIX_HEADER = "Sidebar/Sidebar-Prefix.pch";
INFOPLIST_FILE = "Sidebar/Sidebar-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
LINKER_DISPLAYS_MANGLED_NAMES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -326,10 +328,12 @@
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 = "Sidebar/Sidebar-Prefix.pch";
INFOPLIST_FILE = "Sidebar/Sidebar-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
LINKER_DISPLAYS_MANGLED_NAMES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
8 changes: 4 additions & 4 deletions Sidebar/Sidebar-main.m
Expand Up @@ -9,8 +9,8 @@
#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
}
4 changes: 2 additions & 2 deletions Sidebar/SidebarAppDelegate.h
Expand Up @@ -15,8 +15,8 @@
SidebarViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, strong) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet SidebarViewController *viewController;
@property (nonatomic, strong) IBOutlet SidebarViewController *viewController;

@end
6 changes: 0 additions & 6 deletions Sidebar/SidebarAppDelegate.m
Expand Up @@ -31,11 +31,5 @@ - (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate.
}

- (void)dealloc {

[window release];
[viewController release];
[super dealloc];
}

@end
2 changes: 1 addition & 1 deletion Sidebar/SidebarViewController.h
Expand Up @@ -16,7 +16,7 @@

NSMutableArray *colors;
}
@property (nonatomic, retain) IBOutlet HSImageSidebarView *sidebar;
@property (nonatomic, strong) IBOutlet HSImageSidebarView *sidebar;

- (IBAction)insertRow:(id)sender;
- (IBAction)deleteSelection:(id)sender;
Expand Down
12 changes: 2 additions & 10 deletions Sidebar/SidebarViewController.m
Expand Up @@ -9,7 +9,7 @@
#import "SidebarViewController.h"

@interface SidebarViewController ()
@property (retain) UIPopoverController *popover;
@property (strong) UIPopoverController *popover;
@property (copy) void (^actionSheetBlock)(NSUInteger);

@end
Expand Down Expand Up @@ -136,18 +136,16 @@ -(void)sidebar:(HSImageSidebarView *)sidebar didTapImageAtIndex:(NSUInteger)anIn
[sheet showFromRect:[sidebar frameOfImageAtIndex:anIndex]
inView:sidebar
animated:YES];
[sheet release];

}
}

- (void)sidebar:(HSImageSidebarView *)sidebar didMoveImageAtIndex:(NSUInteger)oldIndex toIndex:(NSUInteger)newIndex {
NSLog(@"Image at index %d moved to index %d", oldIndex, newIndex);

NSNumber *color = [[colors objectAtIndex:oldIndex] retain];
NSNumber *color = [colors objectAtIndex:oldIndex];
[colors removeObjectAtIndex:oldIndex];
[colors insertObject:color atIndex:newIndex];
[color release];
}

- (void)sidebar:(HSImageSidebarView *)sidebar didRemoveImageAtIndex:(NSUInteger)anIndex {
Expand All @@ -159,10 +157,4 @@ -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInt
actionSheetBlock(buttonIndex);
}

- (void)dealloc {
[popover release];
[_sidebar release];
[colors release];
[super dealloc];
}
@end
4 changes: 2 additions & 2 deletions SidebarAdvanced.xcodeproj/project.pbxproj
Expand Up @@ -15,7 +15,7 @@
B79A436E1553964900F45E43 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B79A436D1553964900F45E43 /* AppDelegate.m */; };
B79A43711553964900F45E43 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B79A436F1553964900F45E43 /* MainStoryboard.storyboard */; };
B79A43741553964900F45E43 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B79A43731553964900F45E43 /* RootViewController.m */; };
B79A4381155396C700F45E43 /* HSImageSidebarView.m in Sources */ = {isa = PBXBuildFile; fileRef = B79A437F155396C700F45E43 /* HSImageSidebarView.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
B79A4381155396C700F45E43 /* HSImageSidebarView.m in Sources */ = {isa = PBXBuildFile; fileRef = B79A437F155396C700F45E43 /* HSImageSidebarView.m */; };
B79A43861553984B00F45E43 /* BigLetterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B79A43851553984B00F45E43 /* BigLetterViewController.m */; };
B79A438815539ABD00F45E43 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B79A438715539ABD00F45E43 /* QuartzCore.framework */; };
/* End PBXBuildFile section */
Expand All @@ -36,7 +36,7 @@
B79A43731553964900F45E43 /* RootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
B79A437E155396C700F45E43 /* HSImageSidebarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSImageSidebarView.h; sourceTree = "<group>"; };
B79A437F155396C700F45E43 /* HSImageSidebarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HSImageSidebarView.m; sourceTree = "<group>"; };
B79A4380155396C700F45E43 /* HSImageSidebarViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; path = HSImageSidebarViewDelegate.h; sourceTree = "<group>"; };
B79A4380155396C700F45E43 /* HSImageSidebarViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSImageSidebarViewDelegate.h; sourceTree = "<group>"; };
B79A43841553984B00F45E43 /* BigLetterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BigLetterViewController.h; sourceTree = "<group>"; };
B79A43851553984B00F45E43 /* BigLetterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BigLetterViewController.m; sourceTree = "<group>"; };
B79A438715539ABD00F45E43 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
Expand Down

2 comments on commit 04ccc9f

@cuongdv1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your lib. how to add name of each item in the siderbar?

@bjhomer
Copy link
Owner Author

@bjhomer bjhomer commented on 04ccc9f Jul 17, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.