Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibljon/5957892 to your computer and use it in GitHub Desktop.
Save sibljon/5957892 to your computer and use it in GitHub Desktop.
A solution to resolve a namespace collision between UIImageView categories in SDWebImage and AFNetworking
//
// 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
// 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
Copy link

grav commented May 27, 2014

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