Comparing Results with a List and finding the same object


(Mark spaulding) #1

Hi All,

I need to loop through the objects in the Realm file and see if it is also listed in the List.

When I look at the file with the Realm Browser, it is there, but the following code always renders false.

Can anyone make out what is going on? (I am initiating Try! Realm earlier in the code, it is there, this is just the section that is bobbling my brian. It runs fine BTW.

Thanks,
Blessings,
—Mark

    let totalReg = realm.objects(Registry.self)
    let totalList = realm.objects(AllServices.self)
    
    if totalReg.count != 0 && totalList.count != 0 { // when the update releases, I will change totalList == 0
        
        print(totalReg.count) // = 2 records
        print(totalList.count) // = 1 but when I click and open the list in Realm Browser it shows both records
      
        let a = AllServices().self
        
        
        for reg in totalReg {
            if a.everything.contains(reg) {
                
                print("Here")
            } else {
                print("not here") //Each loop goes here.
                print(a.everything) //this prints: List<Registry> <0x600001d6e070> ( )
                print (reg) //This correctly prints all the properties of the object.
            }
        }
    }