Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions PullToRefreshARCMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ARCMacros.h
// InnerBand
//
// For an explanation of why these work, see:
//
// http://raptureinvenice.com/arc-support-without-branches/
//
// Created by John Blanco on 1/28/12.
// Copyright (c) 2012 Rapture In Venice. All rights reserved.
//
// NOTE: __bridge_tranfer is not included here because releasing would be inconsistent.
// Avoid it unless you're using ARC exclusively or managing it with __has_feature(objc_arc).
//

#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() }
#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];
#endif
3 changes: 2 additions & 1 deletion PullToRefreshView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "PullToRefreshARCMacros.h"

typedef enum {
kPullToRefreshViewStateUninitialized = 0,
Expand All @@ -41,7 +42,7 @@ typedef enum {
@protocol PullToRefreshViewDelegate;

@interface PullToRefreshView : UIView {
id<PullToRefreshViewDelegate> delegate;
__unsafe_unretained id<PullToRefreshViewDelegate> delegate;
UIScrollView *scrollView;
PullToRefreshViewState state;

Expand Down
16 changes: 8 additions & 8 deletions PullToRefreshView.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ - (id)initWithScrollView:(UIScrollView *)scroll {
CGRect frame = CGRectMake(0.0f, 0.0f - scroll.bounds.size.height, scroll.bounds.size.width, scroll.bounds.size.height);

if ((self = [super initWithFrame:frame])) {
scrollView = [scroll retain];
scrollView = SAFE_ARC_RETAIN(scroll);
[scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];

self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Expand Down Expand Up @@ -127,7 +127,7 @@ - (void)refreshLastUpdatedDate {
[formatter setPMSymbol:@"PM"];
[formatter setDateFormat:@"MM/dd/yy hh:mm a"];
subtitleLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [formatter stringFromDate:date]];
[formatter release];
SAFE_ARC_RELEASE(formatter);
}

- (void)beginLoading {
Expand Down Expand Up @@ -229,7 +229,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N

- (void)containingViewDidUnload {
[scrollView removeObserver:self forKeyPath:@"contentOffset"];
[scrollView release];
SAFE_ARC_RELEASE(scrollView);
scrollView = nil;
}

Expand All @@ -238,14 +238,14 @@ - (void)dealloc {

if (scrollView != nil) { // probably leaking the scrollView
NSLog(@"PullToRefreshView: Leaking a scrollView?");
[scrollView release];
SAFE_ARC_RELEASE(scrollView);
}

[arrowImage release];
[statusLabel release];
[subtitleLabel release];
SAFE_ARC_RELEASE(arrowImage);
SAFE_ARC_RELEASE(statusLabel);
SAFE_ARC_RELEASE(subtitleLabel);

[super dealloc];
SAFE_ARC_SUPER_DEALLOC();
}

@end
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ It is:
- a pull-to-refresh implementation
- very easy to implement
- doesn't suck
- compatable with ARC and non-ARC

To implement it:
- add the four files (PullToRefreshView.{h,m}, arrow.png and arrow@2x.png) to your project
- add the five files (PullToRefreshView.{h,m}, ARCMacros.h, arrow.png and arrow@2x.png) to your project
- add the Quartz framework to your project if you haven't done so yet
- #import "PullToRefreshView.h"
- add QuartzCore to your project
Expand Down