[swift-users] Type "T?" does not conform to protocol 'Equatable'
Chris McIntyre
cmcintyre3600 at gmail.com
Mon Feb 29 09:12:34 CST 2016
Int? is not Equatable, b. You would have to use a non-optional.
Under the hood, Optionals are actually an Enum with two cases, None, and Some<T>. func ==(lhs: Int?, rhs: Int?) must be designed essentially as a switch statement to handle each possibility.
--
Chris McIntyre
> On Feb 29, 2016, at 9:24 AM, Rudolf Adamkovič via swift-users <swift-users at swift.org> wrote:
>
> Hi everyone!
>
> I have a generic class similar to this one:
>
> class C<T: Equatable> {
> let t: T
> init(t: T) { self.t = t }
> }
>
> When try to wrap ‘Int?' inside, I get the following error:
>
> let a = C<Int?>(t: nil) // ERROR: Type "Int?" does not conform to protocol 'Equatable'
>
> Yet when I try to compare two ‘Int?’ values, everything works:
>
> let a: Int? = 5
> let b: Int? = 6
>
> let c = a == b // NO ERROR
>
> So, is ‘Int?' equatable or not?
>
> Thanks!
>
> R+
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160229/12d27678/attachment.html>
More information about the swift-users
mailing list