The Swift equatable protocol can be used to have objects use the equality operators for comparison.
Questions tagged [equatable]
144 questions
-1
votes
3 answers
Information on Flutter Bloc pattern to reuse the state and event classes
I am using flutter_bloc package for state management and extends with Equatable. I have made Event class and state class for the data to display which I receive from api. It is the simple app where I am receiving data from api and just to display on…

Harry
- 154
- 4
- 15
-1
votes
1 answer
Binary operator '!=' cannot be applied to two 'any P' operands
I tried this piece of code:
import Foundation
protocol P: Equatable {}
class T {
var p: any P
init(_ pp: any P) {
self.p = pp
}
func update(_ pp: any P) {
if pp != p {
p = pp
}
…

John DoeDoe
- 133
- 1
- 7
-1
votes
1 answer
A way to compare generics in Swift only if they conform to Equatable
Wondering if there's a good way to do this or not:
I have a @propertyWrapper named "Enhanced" that I use. I use the wrappedValue.set to do some actions, and I would also like to do some further actions if the property is Equatable.
Currently, the…

ev0
- 179
- 2
- 7
-1
votes
1 answer
How to type cast an Enum to a Double in Swift
I have a codable Enum, that can take the form of a string OR a double because the JSON response I get can either be in a string or a double. I need to extract the double from the enum but I can't figure out why.
enum greeksEnum: Codable,…

Chris
- 361
- 1
- 4
- 17
-1
votes
1 answer
Flutter app: Can't return value of type "Either" from method because it has a return type of "Either"
Can't figure this one out - especially as the type-error in VSCode and Android Studio is telling me that the types are identical.
Error:
"A value of type 'Either (where Failure is defined in ...lib\core\error\failures.dart)'…

Peter Thompson
- 31
- 7
-1
votes
1 answer
Equatable protocol implementation for undefined property list?
I have a class with Equatable protocol implementation. I know that 2 objects of this class are equal if all their inner variables are equal. Objects may contain arrays. Currently I hardcode each value pair comparison which is not agile.
If there is…

Vyachaslav Gerchicov
- 2,317
- 3
- 23
- 49
-1
votes
1 answer
How does `NSAttibutedString` equate attribute values of type `Any`?
The enumerateAttribute(_:in:options:using:) method of NSAttributedString appears to equate arbitrary instances of type Any. Of course, Any does not conform to Equatable, so that should not be possible.
Question: How does the method compare one…

Matthew Rips
- 501
- 4
- 9
-1
votes
1 answer
Swift : Why is it required for the key type in a Dictionary to be of type Hashable
If I want to create a Dictionary() it is required for the Key type object to the protocol Hashable. Why is that the case, how are Dictionaries implemented?
I mean I would understand that if the Key just needs to conform to the protocol…

rahulg
- 2,183
- 3
- 33
- 47
-1
votes
2 answers
Equatable == function implemented but still crashes
In my app, I have a class Video which implements the Equatable protocol because I need to use the ==(lhs:,rhs:) -> Bool function. My class was as this :
class Video: Equatable {
var url: URL!
// Some other vars
}
func ==(lhs: Video, rhs:…

Thibaut Brnl
- 31
- 5