1

I was able to to do something like this (using version 4.10.1):

extension UIImageView {
    func test() {
        self.kf.indicatorType = .activity
    }
}

now with version 5.0.0 this is no longer possible with the following error:

Cannot assign to property: 'self' is immutable

I still can set it normally from outside the extension. Is there a way to set the indictorType from inside the UIImageView extension?

Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
JAHelia
  • 6,934
  • 17
  • 74
  • 134

2 Answers2

3

As in this issue on the GitHub repository of the library, it turns out that kf variable now refers to a struct for performance considerations in Kingfisher, so to handle it we need to a create a copy for it like the following:

extension UIImageView {
    func test() {
        var kf = self.kf
        kf.indicatorType = .activity
    }
}
Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
JAHelia
  • 6,934
  • 17
  • 74
  • 134
  • 1
    This should be marked as the correct answer. There is also an issue for it: https://github.com/onevcat/Kingfisher/issues/1064 – onevcat Dec 18 '18 at 01:56
1
extension UIImageView {
 func setImages(url:String){
    let activityInd = UIActivityIndicatorView()
    activityInd.center = CGPoint(x: self.frame.size.width  / 2,
                                 y: self.frame.size.height / 2)
    activityInd.color = UIColor.red
    self.addSubview(activityInd)
    activityInd.startAnimating()
    self.kf.setImage(with: URL(string: url), placeholder: #imageLiteral(resourceName: "user-icn"), options: nil, progressBlock: nil) { (img, err, cache, url) in
        activityInd.stopAnimating()
    }
}

}