I have an entity that has a name and for testing purposes I named them in order of most recently added(0) to oldest added object.

When I first launch the app it loads my entities in order(0,1,2...) but if I change the name attribute of any entity the order is all messed up. I use the numberOfRows tableview function to test this as is is called when the tableView is reloaded(correct me if I am wrong):

```
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return 0}
    let managedContext = appDelegate.managedObjectContext
    let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "GraphDataSet")
    do {
        graphSetArray.removeAll()
        graphSetArray = try managedContext.fetch(fetchRequest)
    } catch let error as NSError {
        print("Could not fetch. \(error), \(error.userInfo)")
    }
    for i in 0..<graphSetArray.count{
        let set = graphSetArray[(graphSetArray.count-1)-i]
        print("Name: ", set.value(forKeyPath: "name") as? String)
    }
    return graphSetArray.count
}

```

As far as I understand this empties the Array holding all the entities(although I believe this is pointless as its being set in the next line but I wanted to make sure), then fetches the entities filling the array. I then loop through the array backwards(recent to old) and get the entity of that index and print its name attribute.

This is the console output every time I start the app:

```
Name:  Optional("0")
Name:  Optional("1")
Name:  Optional("2")
Name:  Optional("3")
Name:  Optional("4")
Name:  Optional("5")
Name:  Optional("6")

```

Here is after I change an entities name value to the same value it was(just for the sake of keeping it in order but technically changing the value and reloading the tableView):

```
Name:  Optional("5")
Name:  Optional("4")
Name:  Optional("1")
Name:  Optional("3")
Name:  Optional("0")
Name:  Optional("2")
Name:  Optional("6")

```

Not sure why this happens because I am fetching the data the same way every time, and every time I restart the app the order is back to normal. My only theory is that when an entities attribute is changed that the ordering is messed up with no pattern. So I am wondering whether this theory is correct, and if it is then is there any way to stop the ordering from changing?

EDIT: One thing I just noticed is that after it goes out of order, every time after that when I change the value it maintains this unsorted order