Skip to content

Commit

Permalink
Go all-ARC. Change all property flags to nonatomic. Use proper naming…
Browse files Browse the repository at this point in the history
… conventions.

Signed-off-by: Zachary Waldowski <zwaldowski@gmail.com>
  • Loading branch information
zwaldowski committed Jan 29, 2012
1 parent 7974ff4 commit 5b6103f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 121 deletions.
67 changes: 25 additions & 42 deletions MBProgressHUD.h
Expand Up @@ -84,11 +84,6 @@ typedef enum {

float progress;

#if __has_feature(objc_arc)
id<MBProgressHUDDelegate> __weak delegate;
#else
id<MBProgressHUDDelegate> delegate;
#endif
NSString *labelText;
NSString *detailsLabelText;
float opacity;
Expand Down Expand Up @@ -149,74 +144,68 @@ typedef enum {
* The UIView (i.g., a UIIMageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
* For best results use a 37 by 37 pixel view (so the bounds match the build in indicator bounds).
*/
#if __has_feature(objc_arc)
@property (strong) UIView *customView;
#else
@property (retain) UIView *customView;
#endif
@property (nonatomic, strong) UIView *customView;

/**
* MBProgressHUD operation mode. Switches between indeterminate (MBProgressHUDModeIndeterminate) and determinate
* progress (MBProgressHUDModeDeterminate). The default is MBProgressHUDModeIndeterminate.
*
* @see MBProgressHUDMode
*/
@property (assign) MBProgressHUDMode mode;
@property (nonatomic) MBProgressHUDMode mode;

/**
* The animation type that should be used when the HUD is shown and hidden.
*
* @see MBProgressHUDAnimation
*/
@property (assign) MBProgressHUDAnimation animationType;
@property (nonatomic) MBProgressHUDAnimation animationType;

/**
* The HUD delegate object. If set the delegate will receive HUDWasHidden: callbacks when the HUD was hidden. The
* delegate should conform to the MBProgressHUDDelegate protocol and implement the HUDWasHidden: method.
*/
#if __has_feature(objc_arc)
@property (weak) id<MBProgressHUDDelegate> delegate;
#else
@property (assign) id<MBProgressHUDDelegate> delegate;
#endif
@property (nonatomic, weak) id <MBProgressHUDDelegate> delegate;

/**
* An optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit
* the entire text. If the text is too long it will get clipped by displaying "..." at the end. If left unchanged or
* set to @"", then no message is displayed.
*/
@property (copy) NSString *labelText;
@property (nonatomic, copy) NSString *labelText;

/**
* An optional details message displayed below the labelText message. This message is displayed only if the labelText
* property is also set and is different from an empty string (@"").
*/
@property (copy) NSString *detailsLabelText;
@property (nonatomic, copy) NSString *detailsLabelText;

/**
* The opacity of the HUD window. Defaults to 0.9 (90% opacity).
*/
@property (assign) float opacity;
@property (nonatomic) float opacity;

/**
* The x-axis offset of the HUD relative to the centre of the superview.
*/
@property (assign) float xOffset;
@property (nonatomic) float xOffset;

/**
* The y-ayis offset of the HUD relative to the centre of the superview.
*/
@property (assign) float yOffset;
@property (nonatomic) float yOffset;

/**
* The amounth of space between the HUD edge and the HUD elements (labels, indicators or custom views).
*
* Defaults to 20.0
*/
@property (assign) float margin;
@property (nonatomic) float margin;

/**
* Cover the HUD background view with a radial gradient.
*/
@property (assign) BOOL dimBackground;
@property (nonatomic, getter = dimsBackground) BOOL dimBackground;

/*
* Grace period is the time (in seconds) that the invoked method may be run without
Expand All @@ -227,15 +216,15 @@ typedef enum {
* Grace time functionality is only supported when the task status is known!
* @see taskInProgress
*/
@property (assign) float graceTime;
@property (nonatomic) float graceTime;


/**
* The minimum time (in seconds) that the HUD is shown.
* This avoids the problem of the HUD being shown and than instantly hidden.
* Defaults to 0 (no minimum show time).
*/
@property (assign) float minShowTime;
@property (nonatomic) float minShowTime;

/**
* Indicates that the executed operation is in progress. Needed for correct graceTime operation.
Expand All @@ -245,44 +234,38 @@ typedef enum {
* you need to set this property when your task starts and completes in order to have normal graceTime
* functunality.
*/
@property (assign) BOOL taskInProgress;
@property (nonatomic, getter = isTaskInProgress) BOOL taskInProgress;

/**
* Removes the HUD from it's parent view when hidden.
* Defaults to NO.
*/
@property (assign) BOOL removeFromSuperViewOnHide;
@property (nonatomic) BOOL removeFromSuperViewOnHide;

/**
* Font to be used for the main label. Set this property if the default is not adequate.
*/
#if __has_feature(objc_arc)
@property (strong) UIFont* labelFont;
#else
@property (retain) UIFont* labelFont;
#endif
@property (nonatomic, strong) UIFont *labelFont;

/**
* Font to be used for the details label. Set this property if the default is not adequate.
*/
#if __has_feature(objc_arc)
@property (strong) UIFont* detailsLabelFont;
#else
@property (retain) UIFont* detailsLabelFont;
#endif
@property (nonatomic, strong) UIFont *detailsLabelFont;

/**
* The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0.
*/
@property (assign) float progress;
@property (nonatomic) float progress;

/**
* The minimum size of the HUD bezel. Defaults to CGSizeZero.
*/
@property (assign) CGSize minSize;
@property (nonatomic) CGSize minSize;

/**
* Force the HUD dimensions to be equal if possible.
*/
@property (assign, getter = isSquare) BOOL square;
@property (nonatomic, getter = isSquare) BOOL square;

/**
* Display the HUD. You need to make sure that the main thread completes its run loop soon after this method call so
Expand Down Expand Up @@ -360,7 +343,7 @@ typedef enum {
/**
* Progress (0.0 to 1.0)
*/
@property (nonatomic, assign) float progress;
@property (nonatomic) float progress;

@end

Expand Down
99 changes: 20 additions & 79 deletions MBProgressHUD.m
Expand Up @@ -27,20 +27,13 @@ - (void)hideDelayed:(NSNumber *)animated;
- (void)launchExecution;
- (void)cleanUp;

#if __has_feature(objc_arc)
@property (strong) UIView *indicator;
@property (strong) NSTimer *graceTimer;
@property (strong) NSTimer *minShowTimer;
@property (strong) NSDate *showStarted;
#else
@property (retain) UIView *indicator;
@property (retain) NSTimer *graceTimer;
@property (retain) NSTimer *minShowTimer;
@property (retain) NSDate *showStarted;
#endif

@property (assign) float width;
@property (assign) float height;
@property (nonatomic, strong) UIView *indicator;
@property (nonatomic, strong) NSTimer *graceTimer;
@property (nonatomic, strong) NSTimer *minShowTimer;
@property (nonatomic, strong) NSDate *showStarted;

@property (nonatomic) float width;
@property (nonatomic) float height;

@end

Expand Down Expand Up @@ -158,18 +151,12 @@ - (float)progress {

- (void)updateLabelText:(NSString *)newText {
if (labelText != newText) {
#if !__has_feature(objc_arc)
[labelText release];
#endif
labelText = [newText copy];
}
}

- (void)updateDetailsLabelText:(NSString *)newText {
if (detailsLabelText != newText) {
#if !__has_feature(objc_arc)
[detailsLabelText release];
#endif
detailsLabelText = [newText copy];
}
}
Expand All @@ -184,26 +171,15 @@ - (void)updateIndicators {
}

if (mode == MBProgressHUDModeDeterminate) {
#if __has_feature(objc_arc)
self.indicator = [[MBRoundProgressView alloc] init];
#else
self.indicator = [[[MBRoundProgressView alloc] init] autorelease];
#endif
}
else if (mode == MBProgressHUDModeCustomView && self.customView != nil){
self.indicator = [MBRoundProgressView new];
} else if (mode == MBProgressHUDModeCustomView && self.customView) {
self.indicator = self.customView;
} else {
#if __has_feature(objc_arc)
self.indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
#else
self.indicator = [[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
#endif
[(UIActivityIndicatorView *)indicator startAnimating];
UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[view startAnimating];
self.indicator = view;
}



[self addSubview:indicator];
}

Expand All @@ -222,11 +198,7 @@ + (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:hud];
[hud show:animated];
#if __has_feature(objc_arc)
return hud;
#else
return [hud autorelease];
#endif
}

+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated {
Expand Down Expand Up @@ -322,21 +294,6 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}

#if !__has_feature(objc_arc)
- (void)dealloc {
[indicator release];
[label release];
[detailsLabel release];
[labelText release];
[detailsLabelText release];
[graceTimer release];
[minShowTimer release];
[showStarted release];
[customView release];
[super dealloc];
}
#endif

#pragma mark -
#pragma mark Layout

Expand Down Expand Up @@ -517,15 +474,9 @@ - (void)handleMinShowTimer:(NSTimer *)theTimer {
}

- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {

methodForExecution = method;
#if __has_feature(objc_arc)
targetForExecution = target;
objectForExecution = object;
#else
targetForExecution = [target retain];
objectForExecution = [object retain];
#endif

// Launch execution in new thread
taskInProgress = YES;
Expand All @@ -536,21 +487,16 @@ - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object
}

- (void)launchExecution {
#if !__has_feature(objc_arc)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
@autoreleasepool {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
// Start executing the requested task
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
// Start executing the requested task
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
#pragma clang diagnostic pop
// Task completed, update view in main thread (note: view operations should
// be done only in the main thread)
[self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO];

#if !__has_feature(objc_arc)
[pool release];
#endif
// Task completed, update view in main thread (note: view operations should
// be done only in the main thread)
[self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO];
}
}

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context {
Expand All @@ -575,11 +521,6 @@ - (void)cleanUp {

self.indicator = nil;

#if !__has_feature(objc_arc)
[targetForExecution release];
[objectForExecution release];
#endif

[self hide:useAnimation];
}

Expand Down

0 comments on commit 5b6103f

Please sign in to comment.