<commit_before>#if canImport(UIKit)
import ImageIOSwift
import UIKit

public protocol ImageSourceViewDelegate: AnyObject {
    func imageSourceViewDidUpdate(_ imageSourceView: ImageSourceView)
}

extension ImageSourceViewDelegate {
    public func imageSourceControllerDidUpdate(_: ImageSourceView) {}
}

open class ImageSourceView: UIView {
    public weak var delegate: ImageSourceViewDelegate?
    
    private var controller: ImageSourceController? {
        didSet {
            oldValue?.stopAnimating()
            oldValue?.delegate = nil
            
            self.controller?.delegate = self
            
            self.update()
            
            if window != nil, self.isAnimationEnabled {
                self.controller?.startAnimating()
            }
        }
    }
    
    private var _imageSource: ImageSource? {
        get {
            return controller?.imageSource
        }
        set {
            guard controller?.imageSource !== newValue else { return }
            if let newValue = newValue {
                controller = ImageSourceController(imageSource: newValue)
            } else {
                controller = nil
            }
        }
    }
    
    open var imageSource: ImageSource? {
        get {
            return self._imageSource
        }
        set {
            guard self.controller?.imageSource !== newValue else { return }
            self._imageSource = newValue
            self.task = nil
        }
    }
    
    public var displayedImage: UIImage? {
        return controller?.currentUIImage
    }
    
    fileprivate func update() {
        self.displayView.layer.contents = self.controller?.currentImage
        self.displayView.transform = self.controller?.currentProperties.transform ?? CGAffineTransform.identity
        self.invalidateIntrinsicContentSize()
        
        self.delegate?.imageSourceControllerDidUpdate(self)
    }
    
    // MARK: - URL Loading
    <commit_msg>Fix ImageIOUIKit.ImageSourceView delegate<commit_after>#if canImport(UIKit)
import ImageIOSwift
import UIKit

public protocol ImageSourceViewDelegate: AnyObject {
    func imageSourceViewDidUpdate(_ imageSourceView: ImageSourceView)
}

open class ImageSourceView: UIView {
    public weak var delegate: ImageSourceViewDelegate?
    
    private var controller: ImageSourceController? {
        didSet {
            oldValue?.stopAnimating()
            oldValue?.delegate = nil
            
            self.controller?.delegate = self
            
            self.update()
            
            if window != nil, self.isAnimationEnabled {
                self.controller?.startAnimating()
            }
        }
    }
    
    private var _imageSource: ImageSource? {
        get {
            return controller?.imageSource
        }
        set {
            guard controller?.imageSource !== newValue else { return }
            if let newValue = newValue {
                controller = ImageSourceController(imageSource: newValue)
            } else {
                controller = nil
            }
        }
    }
    
    open var imageSource: ImageSource? {
        get {
            return self._imageSource
        }
        set {
            guard self.controller?.imageSource !== newValue else { return }
            self._imageSource = newValue
            self.task = nil
        }
    }
    
    public var displayedImage: UIImage? {
        return controller?.currentUIImage
    }
    
    fileprivate func update() {
        self.displayView.layer.contents = self.controller?.currentImage
        self.displayView.transform = self.controller?.currentProperties.transform ?? CGAffineTransform.identity
        self.invalidateIntrinsicContentSize()
        
        self.delegate?.imageSourceViewDidUpdate(self)
    }
    
    // MARK: - URL Loading
    
{'fraction_non_alphanumeric': 0.07196870925684486, 'fraction_numerical': 0.0, 'mean_word_length': 1.8541666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2877807', 'n_tokens_mistral': 938, 'n_tokens_neox': 926, 'n_words': 204}