Hi,
i have following swift code:
import UIKit
class ViewController: UIViewController {
let i1 = UIImage()
let i2 = UIImage()
override func viewDidLoad() {
super.viewDidLoad()
i1 == i2 // <------------------- Ambiguous use of operator '=='
}
}
protocol ImageHolder {
func equals(_ o2: ImageHolder) -> Bool
}
func ==(lhs: ImageHolder, rhs: ImageHolder) -> Bool {
lhs.equals(rhs)
}
extension UIImage: ImageHolder {
func equals(_ o2: ImageHolder) -> Bool {
true
}
}
Full error message
~/work/Example/Example/ViewController.swift:16:8: error: ambiguous use of operator '=='
i1 == i2
^
~/work/Example/Example/ViewController.swift:24:6: note: found this candidate
func ==(lhs: ImageHolder, rhs: ImageHolder) -> Bool {
^
ObjectiveC.NSObject:2:24: note: found this candidate
public static func == (lhs: NSObject, rhs: NSObject) -> Bool
And also it could be inside of the generated conformance to Equatable protocol by some Struct with an UIImage property.
Why compiler couldn't infer that i want use ==(lhs: UIImage, rhs: UIImage)
operator of UIImage
s conformance to Equatable instead of global operator ==(lhs: ImageHolder, rhs: ImageHolder)
? Is there any way to fix such errors?