Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #125 from mrackwitz/master

Improved subclassing
  • Loading branch information...
commit 50f23054b16dcff0d867212db2ca448310c9ef1c 2 parents 2065aa5 + ed8f872
Matej Bukovinski matej authored
Showing with 17 additions and 11 deletions.
  1. +10 −2 MBProgressHUD.h
  2. +7 −9 MBProgressHUD.m
12 MBProgressHUD.h
View
@@ -56,6 +56,14 @@ typedef enum {
} MBProgressHUDAnimation;
+#ifndef MB_INSTANCETYPE
+ #if __has_feature(objc_instancetype)
+ #define MB_INSTANCETYPE instancetype
+ #else
+ #define MB_INSTANCETYPE id
+ #endif
+#endif
+
#ifndef MB_STRONG
#if __has_feature(objc_arc)
#define MB_STRONG strong
@@ -111,7 +119,7 @@ typedef void (^MBProgressHUDCompletionBlock)();
* @see hideHUDForView:animated:
* @see animationType
*/
-+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
++ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
/**
* Finds the top-most HUD subview and hides it. The counterpart to this method is showHUDAddedTo:animated:.
@@ -145,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;
++ (MB_INSTANCETYPE)HUDForView:(UIView *)view;
/**
* Finds all HUD subviews and returns them.
16 MBProgressHUD.m
View
@@ -104,15 +104,15 @@ @implementation MBProgressHUD {
#pragma mark - Class methods
-+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
- MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
++ (MB_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];
@@ -122,7 +122,7 @@ + (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];
@@ -130,11 +130,10 @@ + (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated {
return [huds count];
}
-+ (MBProgressHUD *)HUDForView:(UIView *)view {
- Class hudClass = [MBProgressHUD class];
++ (MB_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;
}
}
@@ -144,9 +143,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];
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.