0
votes

Please help me in below code. I'm getting an error:

Expression type "(_, _) -> Void" is ambiguous without more context.

import UIKit
import SDWebImage

class CustomImageView: UIImageView {
    let progressIndicatorView = CircularLoaderView(frame: CGRect.zero)

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!

        addSubview(self.progressIndicatorView)
        progressIndicatorView.frame = bounds
        progressIndicatorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        let url = NSURL(string: "http://png-3.findicons.com/files/icons/2795/office_2013_hd/2000/word.png")
        self.sd_setImage(with: url as URL?, placeholderImage: nil, options: .cacheMemoryOnly, progress: { [weak self] (receivedSize, expectedSize) -> Void in
            self.progressIndicatorView.progress = CGFloat(receivedSize)/CGFloat(expectedSize)
        }) { [weak self](image, error, _, _) -> Void in
            self.progressIndicatorView.reveal()
        }
    }
}
3
When asking questions about compile-time errors, you need to specify on which line the error occurs. It’s not always obvious and forces others to waste time trying to figure that out. - Joshua Nozzi
Looking at SDWebImage implementation, doesn't the progress block declare an URL as the third parameter? - crizzis
What does the signature for sd_setImage look like? - Phillip Mills
Im getting compile error at: self.sd_setImage(with: url as URL?, placeholderImage: nil, options: .cacheMemoryOnly, progress: { [weak self] (receivedSize, expectedSize) -> Void in @Joshua Nozzi - When Key

3 Answers

1
votes

Change NSURL to URL should work!

0
votes

I think it's referring to the [weak self] (receivedSize, expectedSize) -> Void in, which means the function sd.setImage() has more than one progress argument type.

You can probably solve this by explicitly describing the types of receivedSize and expectedSize, as something like [weak self] (receivedSize: Type1, expectedSize: Type2) -> Void in.

0
votes

Its because you are missing one more parameter from the progressBlock. Check This

import UIKit

import SDWebImage

class CustomImageView: UIImageView { let progressIndicatorView = CircularLoaderView(frame: CGRect.zero)

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!

    addSubview(self.progressIndicatorView)
    progressIndicatorView.frame = bounds
    progressIndicatorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

    let url = URL(string: "http://png-3.findicons.com/files/icons/2795/office_2013_hd/2000/word.png")!
    self.sd_setImage(with: url, placeholderImage: nil, options: .cacheMemoryOnly, progress: { (receivedSize, expectedSize, _) in
        self.progressIndicatorView.progress = CGFloat(receivedSize)/CGFloat(expectedSize)
    }) { (image, error, _, _) in

    }
}

}

Seee there should be three of them in progressBlock