Avatar
Avatar
koher
UIView のリファレンス https://developer.apple.com/documentation/uikit/uiview の Conforms To に EquatableHashable がないんだけど( NSObject https://developer.apple.com/documentation/objectivec/nsobject にはある)、これって単にドキュメント上で漏れてるだけ? Equatable に準拠したクラスのサブクラスの Equatable 準拠ってどうなるんだったっけ( ==Self がサブクラスを指さずにスーパークラスを指して UIVeiw にとっての Euatable 準拠になってない?)と思ったけど、↓はできたからサブクラスにとっての Equatable 準拠でいいのかな。 @swift-5.8.1 import Foundation struct Foo<T: Equatable> { func bar(_ x: T, _ y: T) -> Bool { return x == y } } class UIView: NSObject { } let foo: Foo<UIView> = .init() // これが通るので UIView は Equatable 準拠 let a: UIView = .init() let b: UIView = .init() print(a == a) print(a == b)
true false