Search code examples
iosobjective-cswiftsdwebimage

SDWebImage cannot find SDImageCacheType


I'm facing the problem that I cannot use completion block of the SDWebImage library (written in Objective-C). I'm using sd_setImageWithURL in several places, but every time I receive error Use of undeclared type 'SDImageCacheType'. The problem occured on 2 different MacBooks. I checked and the missing type is declared in SDWebImage.h file (attached at the end). I'm using CocoaPods.

How it looks on XCode

Essencial source code

        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)

Briding header essential line

#import <SDWebImage/SDImageCache.h>

The top of the SDImageCache.h file

/*
 * This file is part of the SDWebImage package.
 * (c) Olivier Poitrey <rs@dailymotion.com>
 *
 * 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!

Solution

  • Okey that was a really trivial problem I don't know why I didn't figure it out earlier. All I need to do is to add one import. Looks like if you use declared blocks you need to add it.

    import SDWebImage