Skip to content
Browse files

Replaced fix class type through instancetype and used self in static …

…methods instead of fixed class reference to enable improved subclassing
  • Loading branch information...
1 parent 09284ec commit 973aa1b268448ed94863ad7f872d4be064cef96d @mrackwitz mrackwitz committed Mar 12, 2013
Showing with 9 additions and 11 deletions.
  1. +2 −2 MBProgressHUD.h
  2. +7 −9 MBProgressHUD.m
View
4 MBProgressHUD.h
@@ -119,7 +119,7 @@ typedef void (^MBProgressHUDCompletionBlock)();
* @see hideHUDForView:animated:
* @see animationType
*/
-+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
++ (instancetype)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
/**
* Finds the top-most HUD subview and hides it. The counterpart to this method is showHUDAddedTo:animated:.
@@ -153,7 +153,7 @@ typedef void (^MBProgressHUDCompletionBlock)();
* @param view The view that is going to be searched.
* @return A reference to the last HUD subview discovered.
*/
-+ (MBProgressHUD *)HUDForView:(UIView *)view;
++ (instancetype)HUDForView:(UIView *)view;
/**
* Finds all HUD subviews and returns them.
View
16 MBProgressHUD.m
@@ -98,15 +98,15 @@ @implementation MBProgressHUD {
#pragma mark - Class methods
-+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
- MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
++ (instancetype)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
+ MBProgressHUD *hud = [[self alloc] initWithView:view];
[view addSubview:hud];
[hud show:animated];
return MB_AUTORELEASE(hud);
}
+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated {
- MBProgressHUD *hud = [MBProgressHUD HUDForView:view];
+ MBProgressHUD *hud = [self HUDForView:view];
if (hud != nil) {
hud.removeFromSuperViewOnHide = YES;
[hud hide:animated];
@@ -116,19 +116,18 @@ + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated {
}
+ (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated {
- NSArray *huds = [self allHUDsForView:view];
+ NSArray *huds = [MBProgressHUD allHUDsForView:view];
for (MBProgressHUD *hud in huds) {
hud.removeFromSuperViewOnHide = YES;
[hud hide:animated];
}
return [huds count];
}
-+ (MBProgressHUD *)HUDForView:(UIView *)view {
- Class hudClass = [MBProgressHUD class];
++ (instancetype)HUDForView:(UIView *)view {
NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator];
for (UIView *subview in subviewsEnum) {
- if ([subview isKindOfClass:hudClass]) {
+ if ([subview isKindOfClass:self]) {
return (MBProgressHUD *)subview;
}
}
@@ -138,9 +137,8 @@ + (MBProgressHUD *)HUDForView:(UIView *)view {
+ (NSArray *)allHUDsForView:(UIView *)view {
NSMutableArray *huds = [NSMutableArray array];
NSArray *subviews = view.subviews;
- Class hudClass = [MBProgressHUD class];
for (UIView *aView in subviews) {
- if ([aView isKindOfClass:hudClass]) {
+ if ([aView isKindOfClass:self]) {
[huds addObject:aView];
}
}

0 comments on commit 973aa1b

Please sign in to comment.
Something went wrong with that request. Please try again.