Search code examples
iosswiftkingfisher

How to set indicatorType in KingFisher v5.0.0 from inside an extension on UIImageView?


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?


Solution

  • 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
        }
    }