0

I've succeeded in incorporating SDWebImage (written in Objective-C) with my Swift project - but its still acting a bit funny. Specifically, its giving me an error in the if statement inside the following Closure:

    let completionBlock: SDWebImageCompletionBlock! = { 
        (image:UIImage!, error: NSError!, cacheType:SDImageCacheType, imageURL:NSURL!) -> Void in

        if (image && cacheType == SDImageCacheType.SDImageCacheTypeNone) {
            cell.productImageView.alpha = 0.0
            UIView.animateWithDuration(1.5, animations: {
                cell.productImageView.alpha = 1.0
            })
        }
    }

    cell.productImageView.sd_setImageWithURL(imageURL!, placeholderImage:UIImage(named:"Icon120pix.png"), completed: completionBlock)

The error I'm getting on that if statement is: Use of unresolved identifier 'SDImageCacheTypeNone'

This makes no sense because SDImageCacheTypeNone is one of the values defined in the SDImageCacheType typedef.

By the way, if I take that if statement out and leave just the statements inside it, everything works just fine.

So any ideas what I might be doing wrong here?

2
  • That worked. So is that a Swift thing? The Typedef is called SDImageCacheType, and its values are SDImageCacheTypeNone, SDImageCacheTypeDisk, and SDImageCacheTypeMemory. So because each value contains the name of the typedef itself you just use the part that's different? Meaning None, Disk, and Memory? Or is Objective-C like that too and I just didn't know that?
    – sirab333
    Commented Jun 24, 2015 at 12:14
  • Got it. Thanks! (why not post your comment as an answer so I can mark it as correct and give you credit for it?)
    – sirab333
    Commented Jun 24, 2015 at 12:19

1 Answer 1

4

Have a look at this document in the Enumerations section for a more in depth explanation as to why Swift displays Objective-C enums differently.

Apple Swift Documents

In your code example the way to solve the problem is to use:

SDImageCacheType.None

Instead of

SDImageCacheType.SDImageCacheTypeNone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.