A solution to resolve a namespace collision between UIImageView categories in SDWebImage and AFNetworking

  • Download Gist
UIImageView+HTUIImageCategoryNamespaceConflictResolver.h
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//
// UIImageView+HTUIImageCategoryNamespaceConflictResolver.h
// HotelTonight
//
// Created by Jonathan Sibley on 7/9/13.
// Copyright (c) 2013 Hotel Tonight. All rights reserved.
//
 
@interface UIImageView (HTUIImageCategoryNamespaceConflictResolver)
 
- (void)AF_setImageWithURL:(NSURL *)url;
- (void)AF_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage;
 
- (void)SD_setImageWithURL:(NSURL *)url;
- (void)SD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
 
@end
 
@interface UIImageView (HTUIImageCategoryNamespaceConflictDiscourager)
 
- (void)setImageWithURL:(NSURL *)url __attribute__ ((deprecated));
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage __attribute__ ((deprecated));
 
@end
UIImageView+HTUIImageCategoryNamespaceConflictResolver.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//
// UIImageView+HTUIImageCategoryNamespaceConflictResolver.m
// HotelTonight
//
// Created by Jonathan Sibley on 7/9/13.
// Copyright (c) 2013 Hotel Tonight. All rights reserved.
//
 
#import "UIImageView+HTUIImageCategoryNamespaceConflictResolver.h"
#import "UIImageView+AFNetworking.h"
#import "SDWebImage/UIImageView+WebCache.h"
 
@implementation UIImageView (HTUIImageCategoryNamespaceConflictResolver)
 
#pragma mark - AFNetworking UIImageView category
 
- (void)AF_setImageWithURL:(NSURL *)url {
[self AF_setImageWithURL:url placeholderImage:nil];
}
 
- (void)AF_setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPShouldHandleCookies:NO];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
 
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
}
 
#pragma mark - SDWebImage UIImageView category
 
- (void)SD_setImageWithURL:(NSURL *)url
{
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
}
 
- (void)SD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
{
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.