title: How to sort Results in Realm
body: <p>I am using Realm with Swift. I want to sort "pictures" saved in Realm by <code>PhotoCollectionViewController</code> in the reverse order of date. I don't know what should I do. I would be pleased if you could lend me your wisdom.</p>
  
  <p>Models.swift</p>
  
  <pre><code>import RealmSwift
  
  class Entry: Object {
      @objc dynamic var text = ""
      @objc dynamic var date = Date()
      let pictures = List&lt;Picture&gt;()
      }
  class Picture: Object {
      @objc dynamic var fullImageName = ""
      @objc dynamic var thumbnailName = ""
      @objc dynamic var entry : Entry?
      }
  </code></pre>
  
  <p>PhotoCollectionViewController.swift</p>
  
  <pre><code>import UIKit
  import RealmSwift
  
  class PhotoCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
  
      var pictures : Results&lt;Picture&gt;?
  
      override func viewWillAppear(_ animated: Bool) {
          getPictures()
      }
  
      func getPictures() {
          if let realm = try? Realm() {
              pictures = realm.objects(Picture.self)
              //I want to sort pictures in the reverse order of date
              collectionView?.reloadData()
          }
      }
  …
  }
  </code></pre>