title: Core Data: Sorting by date not working properly
body: <p>I'm trying to sort my Core Data items by date. When creating a new item it would sort correctly by date added (newest to oldest) but after creating more than 3 it would stop being in order and would display randomly in the list.</p>
  <pre><code>@objc(MyBookmark)
  public class MyBookmark: NSManagedObject, BaseModel {
      static var all: NSFetchRequest&lt;MyBookmark&gt; {
          
          
          
          let request: NSFetchRequest&lt;MyBookmark&gt; = MyBookmark.fetchRequest()
          request.sortDescriptors = [NSSortDescriptor(keyPath: \MyBookmark.timestamp, ascending: true)]
          return request
             
      }
      
  }
  
  
  extension MyBookmark {
  
      @nonobjc public class func fetchRequest() -&gt; NSFetchRequest&lt;MyBookmark&gt; {
          return NSFetchRequest&lt;MyBookmark&gt;(entityName: &quot;MyBookmark&quot;)
      }
  
      @NSManaged public var name: String?
      @NSManaged public var url: String?
      @NSManaged public var timestamp: Date
  
  }
  
  extension MyBookmark : Identifiable {
  
  }
  </code></pre>
  <p>I tested out sorting 'MyBookmark' by name and it works perfectly. The 'timestamp' attribute wasn't there before and i just added it to the model.</p>
  <p><a href="https://i.stack.imgur.com/C6zI1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C6zI1.png" alt="enter image description here" /></a></p>
  <pre><code>struct MyBookmarkViewModel: Identifiable, Hashable{
      
      init(myBM: MyBookmark) {
          self.myBM = myBM
          
      }
      private let myBM: MyBookmark
      
      var id: NSManagedObjectID {
          myBM.objectID
      }
      
      var name: String {
          myBM.name ?? &quot;&quot;
      }
      
      var url: String {
          myBM.url ?? &quot;&quot;
      }
      
      var timestamp: Date {
          myBM.timestamp ?? Date()
      }
  
     
  }
  </code></pre>
  <p>ContentView</p>
  <pre><code>@ObservedObject var vm : MyBookmarksViewModel
  
                ForEach(vm.myBookmarks) { myBookmark in   
    
                      Text(myBookmark.name)
                      Text(myBookmark.date, itemFormatter)   
                      
                            }
      
      
                 private let itemFormatter: DateFormatter = {
                 let formatter = DateFormatter()
                 formatter.dateStyle = .short
                 formatter.timeStyle = .medium
                 return formatter
                  }()
  </code></pre>
  <p>*<strong>Update</strong></p>
  <p>The timestamps in the Content View of all items are exactly the same. When adding a new item, the older items update to the same time as the new one.</p>