Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

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

View UIImageView+HTUIImageCategoryNamespaceConflictResolver.h
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
View UIImageView+HTUIImageCategoryNamespaceConflictResolver.h
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
grav commented

To get Xcode to stop the build if one of the clashing methods are used, you can add a Run script-build phase with the following:

! grep -in -r -e ' setImageWithURL:[^:]*];' . --include "*.m"

It will actually show the error inline in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.