【发布时间】:2015-03-25 04:03:40
【问题描述】:
我在以下代码中看到编译器警告“找不到实例方法 -cacheKeyForURL”和“找不到实例方法 -defaultCachePathForKey”:
SDWebImageManager *manager = [SDWebImageManager sharedManager];
NSString *cacheKey = [manager cacheKeyForURL:[NSURL URLWithString:imageUrl]];
NSString *cachePath = [[manager imageCache] defaultCachePathForKey:cacheKey];
但很明显,这些方法是有定义的。例如,这里是method definition in SDImageCache.h:
/**
* Get the default cache path for a certain key
*
* @param key the key (can be obtained from url using cacheKeyForURL)
*
* @return the default cache path
*/
- (NSString *)defaultCachePathForKey:(NSString *)key;
在我的代码文件的顶部,我包含了来自 SDWebImage 项目的相关文件:
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/SDImageCache.h>
#import <SDWebImage/SDWebImageManager.h>
此外,sharedImageManager is defined 在 SDWebImageManager.h 中,编译器在找到它时没有问题。我只有第 2 行和第 3 行的警告。
我的代码运行良好,这些方法都可以正常工作而不会崩溃。为什么编译器告诉我找不到它?
我正在运行 XCode 6,仅针对 Active Architecture 进行编译,iPhone 6 Simulator。
更新
当我为 Distribution 编译“All Architectures”时,它突然可以找到 cacheKeyForURL 和 defaultCachePathForKey,没问题,但 setImageWithURL 现在已弃用?
我确实看到了deprecation warnings in UIImageView+WebCache.h,但我只是非常困惑为什么当 SDWebImage 的头文件似乎没有任何特定于架构的东西时,为这些不同的架构构建会打开/关闭各种编译器警告他们。
【问题讨论】:
-
您使用的是哪个版本的
SDWebImage?在新版本中有一个sd_setImageWithURL。所以你能确认一下吗?您可以从此链接使用 https://github.com/rs/SDWebImage -
版本 3.7.1,根据 Podfile.lock
标签: objective-c xcode compiler-warnings sdwebimage