The Swift equatable protocol can be used to have objects use the equality operators for comparison.
Questions tagged [equatable]
144 questions
10
votes
2 answers
Flutter: Equatable props getter with optional parameter
I have an object that extends Equatable and contains optional parameters. If I try to add that parameter into the props getter, I get an error The element type 'String?' can't be assigned to the list type 'Object'. However, not adding it would imply…

Jacobo Koenig
- 11,728
- 9
- 40
- 75
9
votes
1 answer
Flutter bloc state does not update state when updating List/array index
I'm trying to implement checkbox logic in bloc class. For that I create List checked in bloc class code is below. When CheckBoxClicked event trigger then for the first time state updated and I can see the box checked.
class…

Abdullah Khan
- 1,365
- 15
- 15
8
votes
2 answers
Passing properties to the super constructor of Equatable
I'm quite new to Flutter and Dart, and I have some troubles understanding how to rewrite a class extending an updated version of Equatable.
This works with Equatable 0.4.0:
abstract class Failure extends Equatable {
Failure([List properties =…

Yako
- 3,405
- 9
- 41
- 71
8
votes
3 answers
RealmObject Equatable redundant message
We have a simple class Person which inherent from realms Object.
Now we want that subclass to conform to the Equatable protocol. The very simple code looks like this.
class Person: Object, Equatable {
dynamic var localID = "0"
dynamic…

Thomas G.
- 1,003
- 12
- 27
7
votes
2 answers
Value of protocol type 'Any' cannot conform to 'Equatable'; only struct/enum/class types can conform to protocols
Value of protocol type 'Any' cannot conform to 'Equatable'; only struct/enum/class types can conform to protocols
Value is type "ANY" as it can be Int or String. So not able to implement Equatable protocol.
struct BusinessDetail:Equatable {
…

pankaj nigam
- 381
- 1
- 6
- 9
6
votes
1 answer
UIImage not equivalent when encoding/decoding
I've been doing some tests on my models to make sure they are equal when I encode them into JSON and then decode them back using JSONEncoder/Decoder. However, one of my tests failed, and the culprit was UIImage. I've made sure that no errors were…

PrayForTech
- 353
- 2
- 10
6
votes
2 answers
func == from equatable protocol does not work for custom object, swift
My goal is to show a user list of history logins ( such as username ) if there are any. In order to do that, I am doing
1. Create an custom object named User like below
class User: NSObject
{
var login: String
init(login:…

tonytran
- 1,068
- 2
- 14
- 24
6
votes
3 answers
Swift: Hashable struct with dictionary property
I have a struct in Swift that looks like this:
internal struct MapKey {
internal let id: String
internal let values: [String:String]
}
extension MapKey: Equatable {}
func ==(lhs: MapKey, rhs: MapKey) -> Bool {
return lhs.id == rhs.id &&…

unbekant
- 1,555
- 22
- 31
5
votes
2 answers
Automatic synthesis of Equatable conformance for Swift struct or enum through an extension
Swift docs say that automatic synthesis of Equatable conformance is available for structs, and enums with associated values, only if conformance is declared in the original definition of the struct or enum, and not through an extension, in which…

Khawer K
- 105
- 1
- 6
5
votes
2 answers
what does the child class of Equatable pass to the super(Equatable class)?
hi I am new with bloc in flutter and I'm trying to understand block timer In the doc of flutter_bloc and I would know what's this constructor class mean
@immutable
abstract class TimerState extends Equatable {
final int duration;
//and this…

B.Ghost
- 200
- 4
- 15
5
votes
2 answers
How to implement Equatable protocol for a protocol based on the identity of two instances that implement this protocol?
I am trying to implement the Equatable protocol for a protocol based on the left' and right's operand identity. I other words: How do I implement the Equatable protocol for a protocol to determine if two instances that implement this protocol (in my…

salocinx
- 3,715
- 8
- 61
- 110
5
votes
3 answers
How does CLLocation implement the Equatable protocol?
In answering another question on SO, I found that the CLLocation class conforms to the Equatable protocol. What method does it use to determine equality?
Exact match of lat/long? Exact match of lat/long and altitude? Exact match of latitude,…

Duncan C
- 128,072
- 22
- 173
- 272
5
votes
1 answer
Swift: Is there a way to test if object cast as AnyObject conforms to Equatable?
I have an object that has keyed properties:
func value(key: String) -> AnyObject?
func setValue(value: AnyObject?, key: String)
I wish to check if the value returned from the value function with the same key from two different objects are…

Rob
- 4,149
- 5
- 34
- 48
4
votes
2 answers
AnyObject try cast to Equatable
I have an Equatable class
class Item: Equatable {
var value: AnyObject?
var title: String
init(title: String, value: AnyObject?) {
self.title = title
self.value = value
}
//Equatable
public static func ==(lhs:…

EvGeniy Ilyin
- 1,817
- 1
- 21
- 38
4
votes
3 answers
Index(of:) and Equatable Protocol
class Person: Equatable {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
static func ==(lhs: Person, rhs: Person) -> Bool {
return (lhs.name == rhs.name) && (lhs.age == rhs.age)
}
}
let p1…

Frankie
- 185
- 1
- 1
- 13