Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@grav

grav 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.

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