【问题标题】:Why is compiler reporting SDWebImageManager defaultCachePathForKey not found?为什么编译器报告 SDWebImageManager defaultCachePathForKey not found?
【发布时间】: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 definedSDWebImageManager.h 中,编译器在找到它时没有问题。我只有第 2 行和第 3 行的警告。

我的代码运行良好,这些方法都可以正常工作而不会崩溃。为什么编译器告诉我找不到它?

我正在运行 XCode 6,仅针对 Active Architecture 进行编译,iPhone 6 Simulator。

更新

当我为 Distribution 编译“All Architectures”时,它突然可以找到 cacheKeyForURLdefaultCachePathForKey,没问题,但 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


【解决方案1】:

我通过更仔细地检查“报告导航器”(neé Log Navigator)中的错误发现了这一点。

事实证明,它选择链接的“派生数据”文件夹中有一些非常旧的 SDWebImageManager.h 文件。不清楚为什么他们没有清理我的项目。 (可能与我从子模块迁移到通过 Cocoapods 包含 SDWebImage 的事实有关?)

used this answer on Stack Overflow 导航到我的 DerivedData 文件夹,然后我手动删除了我的项目的子文件夹。完成此操作后,该项目现在可以成功构建,而不会出现虚假警告。

【讨论】:

    猜你喜欢
    • 2012-12-06
    • 2012-09-20
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多