0

im using websocket and DiffableDataSource, when do search i filter my list and show results. if i switch on/off button of a cell and after deleting text and creating table again button app crashes.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Fatal: supplied identifiers are not unique.' ***

all of my id's are unique but still gettin this error.

enum Section {
    case first
}

struct PairModel {
    let uuid = UUID()
    
    var symbol: String
    var name: String
    var price: Double
    var dailyPercent: Double
    var hasSubscribed: Bool
    var isAd: Bool
    var alertType: String
    var alertDate: String
    var adModel: AdModel?
    var pairId: Int
    var orderNumber: Int
    
    struct AdModel {
        let uuid = UUID()
        let mobileAd: GADNativeAd
    }
    
    
extension PairModel: Hashable {
    static func ==(lhs: PairModel, rhs: PairModel) -> Bool {
        return lhs.uuid == rhs.uuid
    }

    func hash(into hasher: inout Hasher) {
        hasher.combine(uuid)
    }
}

extension PairModel.AdModel: Hashable {
    static func ==(lhs: PairModel.AdModel, rhs: PairModel.AdModel) -> Bool {
        return lhs.uuid == rhs.uuid
    }

    func hash(into hasher: inout Hasher) {
        hasher.combine(uuid)
    }
}
Yosujiro
  • 1
  • 3
  • here is https://stackoverflow.com/questions/62659055/identifiable-protocol-in-swift-class-vs-struct https://developer.apple.com/documentation/swift/identifiable – Gagan_iOS Mar 29 '22 at 12:17
  • A uuid is probably not a great choice when combined with structs. Your identifiers will be unique, but not consistent; each time you create a new instance you will get a new id, even if the instance represents the same item. You need to show the code where you use the identifiers. – Paulw11 Mar 29 '22 at 17:31

0 Answers0