我面临的问题是无法使用SDWebImage库(用Objective-C编写)的完成 block 。我在多个地方使用 sd_setImageWithURL
,但每次收到错误使用未声明的类型“SDImageCacheType”。该问题出现在 2 台不同的 MacBook 上。我检查了一下,缺少的类型在 SDWebImage.h
文件中声明(附在最后)。我正在使用 CocoaPods。
基本源代码
imageViewMain.sd_setImageWithURL(NSURL(string: finalURL)) //Works fine
// Doesn't work.
let b : SDImageCacheType = SDImageCacheType.None
let block = {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType.None, imageURL: NSURL!) -> Void in
println(self)
}
imageViewMain.sd_setImageWithURL(NSURL(string: finalURL), completed: block)
桥接 header 基本行
#import <SDWebImage/SDImageCache.h>
SDImageCache.h
文件顶部
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd8f8ebd999c949184909289949293d39e9290" rel="noreferrer noopener nofollow">[email protected]</a>>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import <Foundation/Foundation.h>
#import "SDWebImageCompat.h"
typedef NS_ENUM(NSInteger, SDImageCacheType) {
/**
* The image wasn't available the SDWebImage caches, but was downloaded from the web.
*/
SDImageCacheTypeNone,
/**
* The image was obtained from the disk cache.
*/
SDImageCacheTypeDisk,
/**
* The image was obtained from the memory cache.
*/
SDImageCacheTypeMemory
};
Podfile
pod 'SDWebImage's'
use_frameworks!
最佳答案
好吧,这是一个非常微不足道的问题,我不知道为什么我没有早点弄清楚。我需要做的就是添加一个导入。看起来如果您使用声明的 block ,您需要添加它。
import SDWebImage
关于ios - SDWebImage 找不到 SDImageCacheType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32483112/