Created
July 9, 2013 14:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
It will actually show the error inline in the code.