We had a piece of code that was working without a problem before, but now when I compile with the latest beta I get this error (this was working with beta 1).
here is the code
import UIKit
extension Optional where Wrapped: UIView {
var isHidden: Bool {
guard let unwrappedSelf = self else { return true }
return unwrappedSelf.isHidden
}
}
protocol MyViewProtocol: UIView {}
class MyView: UIView, MyViewProtocol {}
let view: MyViewProtocol? = MyView()
view.isHidden
the error I get from the compiler are these :
xpression failed to parse:
error: compilerProblemXcode14.playground:15:1: error: property 'isHidden' requires that 'any MyViewProtocol' inherit from 'AnyObject'
view.isHidden
^
compilerProblemXcode14.playground:3:1: note: where 'Wrapped' = 'any MyViewProtocol', 'UIView' = 'AnyObject'
extension Optional where Wrapped: UIView {
^
I tried adding the AnyObject to the MyViewProtocol
but it doesn't work.
I can workaround by not using my extension or casting my view as a UIView. or doing this
view?.isHidden ?? true
but I don't understand why the compiler is blocking us, we are surely doing something wrong but I can't see what.
Thanks for anyone that will take time to read this .
(I sadly can't update the playground)