For an array only the last row is inserted where print shows the loop is processed for index in 0..<model.dataTable!.rows.count {
let row = model.dataTable!.rows[index]
catagory.name = row["Catagory"] as! String
context.insert(catagory)
print(catagory.name)
}
tried a forced try?save() which didn't help Thanks Joel
You have a single Category object that you update inside the loop instead of creating a new category for each iteration.
Remove the category
property and change your loop to something like this
for index in 0..<model.dataTable!.rows.count {
let row = model.dataTable!.rows[index]
let name = row["Catagory"] as! String
let category = Category(id: UUID(), name: name, instrumen: [[)
context.insert(catagory)
print(catagory.name)
}