Sort is swift doubles the number of entries in array

class InventoryModel: ObservableObject {

    @Published var fileData = [inventoryEntry]()

    var fileData2 = [inventoryEntry]() // for debug viewing fileData

    var fileData3 = [inventoryEntry]() // for debug viewing fileData

.....
}



struct inventoryEntry{

    var id: UUID = UUID()

    var name: String = ""

    var catagory: String = ""

    var subcatagory: String = ""

    var location: String = ""

}



inventoryModel.fileData.sort{$0.name < $1.name}



before sort the array has 64 entries and it is also stored in fileData2 viewable at break point

after sort the array has 127 entries and I store hit in fileData3 viewable at break point



What happened here. I did not expect sorting the array to add copied entries



I consider this a bug. bug?
Please format the code with <> tool:

Code Block
class InventoryModel: ObservableObject {
@Published var fileData = [inventoryEntry]()
var fileData2 = [inventoryEntry]() // for debug viewing fileData
var fileData3 = [inventoryEntry]() // for debug viewing fileData
// .....
}
struct inventoryEntry {
var id: UUID = UUID()
var name: String = ""
var catagory: String = ""
var subcatagory: String = ""
var location: String = ""
}

Could you show more code ?
Code Block
inventoryModel.fileData.sort{$0.name < $1.name}

I consider this a bug. bug?

I have never heard of this sort of bugs found in Swift Standard Library. So, it is very likely a bug of your code.
You may be doing something wrong from somewhere you have not shown yet.
Or may be accessing the Array from multiple threads.

Can you show a complete code which can reproduce the same issue?
I actually found a rogue line I had added which caused what happened and it was not the sort. It did take some very detailed debugging to find. Sort is off the hook this time. After 50 some years of coding I can still create bugs requiring very detailed debugging. Still have a few features to get working but it runs on my iPar Air and my Mac Pro and looks good so far.
For those who spent some time looking at your problem, could you tell what the 'rogue line' was ?
Sort is swift doubles the number of entries in array
 
 
Q