Skip to content

Commit

Permalink
[Issue #2381] Using static char declaration pointers for associated o…
Browse files Browse the repository at this point in the history
…bject keys in UIButton category
  • Loading branch information
mattt committed Nov 17, 2014
1 parent 1104eb7 commit da67eae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions UIKit+AFNetworking/UIButton+AFNetworking.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

/**
This category adds methods to the UIKit framework's `UIButton` class. The methods in this category provide support for loading remote images and background images asynchronously from a URL.
@warning Compound values for control `state` (such as `UIControlStateHighlighted | UIControlStateDisabled`) are unsupported.
*/
@interface UIButton (AFNetworking)

Expand Down
34 changes: 32 additions & 2 deletions UIKit+AFNetworking/UIButton+AFNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,23 @@ + (NSOperationQueue *)af_sharedImageRequestOperationQueue {

#pragma mark -

static char AFImageRequestOperationNormal;
static char AFImageRequestOperationHighlighted;
static char AFImageRequestOperationSelected;
static char AFImageRequestOperationDisabled;

static const char * af_imageRequestOperationKeyForState(UIControlState state) {
return [[NSString stringWithFormat:@"af_imageRequestOperationKeyForState_%lu", (unsigned long)state] cStringUsingEncoding:NSASCIIStringEncoding];
switch (state) {
case UIControlStateHighlighted:
return &AFImageRequestOperationHighlighted;
case UIControlStateSelected:
return &AFImageRequestOperationSelected;
case UIControlStateDisabled:
return &AFImageRequestOperationDisabled;
case UIControlStateNormal:
default:
return &AFImageRequestOperationNormal;
}
}

- (AFHTTPRequestOperation *)af_imageRequestOperationForState:(UIControlState)state {
Expand All @@ -65,8 +80,23 @@ - (void)af_setImageRequestOperation:(AFHTTPRequestOperation *)imageRequestOperat

#pragma mark -

static char AFBackgroundImageRequestOperationNormal;
static char AFBackgroundImageRequestOperationHighlighted;
static char AFBackgroundImageRequestOperationSelected;
static char AFBackgroundImageRequestOperationDisabled;

static const char * af_backgroundImageRequestOperationKeyForState(UIControlState state) {
return [[NSString stringWithFormat:@"af_backgroundImageRequestOperationKeyForState_%lu", (unsigned long)state] cStringUsingEncoding:NSASCIIStringEncoding];
switch (state) {
case UIControlStateHighlighted:
return &AFBackgroundImageRequestOperationHighlighted;
case UIControlStateSelected:
return &AFBackgroundImageRequestOperationSelected;
case UIControlStateDisabled:
return &AFBackgroundImageRequestOperationDisabled;
case UIControlStateNormal:
default:
return &AFBackgroundImageRequestOperationNormal;
}
}

- (AFHTTPRequestOperation *)af_backgroundImageRequestOperationForState:(UIControlState)state {
Expand Down

0 comments on commit da67eae

Please sign in to comment.