Skip to content

Commit

Permalink
Migrated to ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenofex committed May 9, 2012
1 parent fd2f8ea commit 433e29e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 52 deletions.
4 changes: 4 additions & 0 deletions StreamView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
459542FF14C55616002BFF69 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "StreamView/StreamView-Prefix.pch";
INFOPLIST_FILE = "StreamView/StreamView-Info.plist";
Expand All @@ -376,6 +377,7 @@
4595430014C55616002BFF69 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "StreamView/StreamView-Prefix.pch";
INFOPLIST_FILE = "StreamView/StreamView-Info.plist";
Expand All @@ -389,6 +391,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/StreamView.app/StreamView";
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
Expand All @@ -406,6 +409,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/StreamView.app/StreamView";
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
Expand Down
10 changes: 2 additions & 8 deletions StreamView/EKAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ @implementation EKAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;

- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[[EKViewController alloc] initWithNibName:@"EKViewController" bundle:nil] autorelease];
self.viewController = [[EKViewController alloc] initWithNibName:@"EKViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Expand Down
7 changes: 4 additions & 3 deletions StreamView/EKStreamView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@property (nonatomic, assign) NSUInteger index;

// You SHOULD ONLY access this property when this object is in visibleCellInfo!
@property (nonatomic, assign) UIView<EKResusableCell> *cell;
@property (nonatomic, unsafe_unretained) UIView<EKResusableCell> *cell;

@end

Expand All @@ -49,7 +49,7 @@


@interface EKStreamViewUIScrollViewDelegate : NSObject<UIScrollViewDelegate>
@property (nonatomic, assign) EKStreamView *streamView;
@property (nonatomic, unsafe_unretained) EKStreamView *streamView;

@end

Expand All @@ -65,9 +65,10 @@
NSSet *visibleCellInfo;
UIView *headerView, *footerView;
CGFloat columnWidth;
EKStreamViewUIScrollViewDelegate *delegateObj;
}

@property (nonatomic, assign) id<EKStreamViewDelegate> delegate;
@property (nonatomic, unsafe_unretained) id<EKStreamViewDelegate> delegate;
@property (nonatomic, assign) CGFloat columnPadding;
@property (nonatomic, assign) CGFloat cellPadding;

Expand Down
32 changes: 9 additions & 23 deletions StreamView/EKStreamView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (NSUInteger)hash

- (NSString *)description
{
return [NSString stringWithFormat:@"<EKWaterfallCellInfo: index: %d>", index];
return [NSString stringWithFormat:@"<%@: index: %d>",NSStringFromClass([self class]), index];
}

@end
Expand All @@ -39,8 +39,8 @@ - (void)setup;
- (NSSet *)getVisibleCellInfo;
- (void)layoutCellWithCellInfo:(EKStreamViewCellInfo *)info;

@property (nonatomic, retain) NSSet *visibleCellInfo;
@property (nonatomic, retain) NSMutableDictionary *cellCache;
@property (nonatomic) NSSet *visibleCellInfo;
@property (nonatomic) NSMutableDictionary *cellCache;

@end

Expand Down Expand Up @@ -79,19 +79,6 @@ - (id)initWithCoder:(NSCoder *)coder
return self;
}

- (void)dealloc
{
[[super delegate] release];
[cellHeightsByIndex release];
[cellHeightsByColumn release];
[rectsForCells release];
[visibleCellInfo release];
[cellCache release];

[headerView release];
[footerView release];
[super dealloc];
}

- (void)reloadData
{
Expand All @@ -107,7 +94,7 @@ - (void)reloadData
}

if ([delegate respondsToSelector:@selector(headerForStreamView:)]) {
headerView = [[delegate headerForStreamView:self] retain];
headerView = [delegate headerForStreamView:self];
CGRect f = headerView.frame;
f.origin = CGPointMake(columnPadding, cellPadding);
headerView.frame = f;
Expand All @@ -118,7 +105,7 @@ - (void)reloadData
}

if ([delegate respondsToSelector:@selector(footerForStreamView:)]) {
footerView = [[delegate footerForStreamView:self] retain];
footerView = [delegate footerForStreamView:self];
[self addSubview:footerView];
} else {
footerView = nil;
Expand Down Expand Up @@ -161,7 +148,7 @@ - (void)reloadData
NSMutableArray *cellHeightsInCol = [cellHeightsByColumn objectAtIndex:shortestCol];
[cellHeightsInCol addObject:[NSNumber numberWithFloat:height]];
NSMutableArray *rectsForCellsInCol = [rectsForCells objectAtIndex:shortestCol];
EKStreamViewCellInfo *info = [[EKStreamViewCellInfo new] autorelease];
EKStreamViewCellInfo *info = [EKStreamViewCellInfo new];
info.frame = CGRectMake(cellX[shortestCol], columnHeights[shortestCol] + cellPadding, columnWidth, height);
info.index = i;
[rectsForCellsInCol addObject:info];
Expand All @@ -171,8 +158,7 @@ - (void)reloadData


// determine the visible cells' range
[visibleCellInfo release];
visibleCellInfo = [[self getVisibleCellInfo] retain];
visibleCellInfo = [self getVisibleCellInfo];

// draw the visible cells

Expand Down Expand Up @@ -208,7 +194,7 @@ - (void)reloadData
NSMutableArray *cellArray = [cellCache objectForKey:identifier];
id<EKResusableCell> cell = nil;
if ([cellArray count] > 0) {
cell = [[[cellArray lastObject] retain] autorelease];
cell = [cellArray lastObject];
[cellArray removeLastObject];
}

Expand Down Expand Up @@ -260,7 +246,7 @@ - (void)layoutCellWithCellInfo:(EKStreamViewCellInfo *)info

- (void)setup
{
EKStreamViewUIScrollViewDelegate *delegateObj = [EKStreamViewUIScrollViewDelegate new];
delegateObj = [EKStreamViewUIScrollViewDelegate new];
delegateObj.streamView = self;
[super setDelegate:delegateObj];

Expand Down
2 changes: 1 addition & 1 deletion StreamView/EKViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
int page;
}

@property (retain, nonatomic) IBOutlet EKStreamView *stream;
@property ( nonatomic) IBOutlet EKStreamView *stream;

@end
13 changes: 3 additions & 10 deletions StreamView/EKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
@implementation EKViewController
@synthesize stream;

- (void)dealloc
{
[randomHeights release];
[stream release];
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
Expand All @@ -34,7 +28,6 @@ - (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[randomHeights release];
randomHeights = [[NSMutableArray alloc] initWithCapacity:100];
for (int i = 0; i < 100; i++) {
CGFloat h = arc4random() % 200 + 50.f;
Expand Down Expand Up @@ -86,7 +79,7 @@ - (UIView *)streamView:(EKStreamView *)streamView cellAtIndex:(NSInteger)index
cell = (MyCell *)[streamView dequeueReusableCellWithIdentifier:CellID];

if (cell == nil) {
cell = [[[MyCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] autorelease];
cell = [[MyCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
cell.reuseIdentifier = CellID;
if (redCell) cell.label.textColor = [UIColor redColor];
}
Expand All @@ -103,7 +96,7 @@ - (CGFloat)streamView:(EKStreamView *)streamView heightForCellAtIndex:(NSInteger

- (UIView *)headerForStreamView:(EKStreamView *)streamView
{
MyCell *header = [[[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - stream.columnPadding * 2, 60)] autorelease];
MyCell *header = [[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - stream.columnPadding * 2, 60)];
header.label.text = @"This is the header";

return header;
Expand All @@ -112,7 +105,7 @@ - (UIView *)headerForStreamView:(EKStreamView *)streamView
- (UIView *)footerForStreamView:(EKStreamView *)streamView
{
if (page <= MaxPage) {
MyCell *footer = [[[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - stream.columnPadding * 2, 60)] autorelease];
MyCell *footer = [[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - stream.columnPadding * 2, 60)];
footer.label.text = @"This is the footer";

return footer;
Expand Down
8 changes: 1 addition & 7 deletions StreamView/MyCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ @implementation MyCell
@synthesize label, reuseIdentifier;


- (void)dealloc
{
[label release];
[reuseIdentifier release];
[super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
CGRect bgFrame = CGRectInset(self.bounds, 0.0f, 0.0f);
UIView *bgView = [[[UIView alloc] initWithFrame:bgFrame] autorelease];
UIView *bgView = [[UIView alloc] initWithFrame:bgFrame];
bgView.layer.borderColor = [UIColor blackColor].CGColor;
bgView.layer.borderWidth = 2.0f;
[self addSubview:bgView];
Expand Down

0 comments on commit 433e29e

Please sign in to comment.