title: How to query realm swift for a specific object
body: <p>Edited to simplify my question...</p>
  
  <p>I'm new to Realm and so far, it's pretty cool, but I'm having an extremely hard time figuring out how to querying my Realm DB to check if a specific item exists in it.</p>
  
  <p>Here's my Realm Model:</p>
  
  <pre><code>import Foundation
  import RealmSwift
  
  class ChartCount: Object{
  
      dynamic var date: Date = Date()
      dynamic var count: Int = Int(0)
  }
  </code></pre>
  
  <p>In my main ViewController I'm storing a series of ChartCount objects for the 7 days of the current week using the following function:</p>
  
  <pre><code>// function to check if this weeks days have been created in Realm DB yet and creates them if not
      let realm = try! Realm()
      lazy var visitors: Results&lt;VisitorCount&gt; = { self.realm.objects(VisitorCount.self)}()
      let startOfWeekDate = Date().startOfWeek(weekday: 1)
      let nextDay = 24 * 60 * 60
  
      var startOfWeek = try! Realm().objects(VisitorCount.self)
  
  func setThisWeeksDays(){
              if charts.count == 0 {
                  try! realm.write() {
  
  
                      let defaultVisitorDates = [startOfWeekDate, startOfWeekDate + TimeInterval(nextDay), startOfWeekDate + TimeInterval(nextDay*2), startOfWeekDate + TimeInterval(nextDay*3), startOfWeekDate + TimeInterval(nextDay*4), startOfWeekDate + TimeInterval(nextDay*5), startOfWeekDate + TimeInterval(nextDay*6)]
  
                      for visitors in defaultChartrDates {
                          let newChartDate = ChartCount()
                          newChartDate.date = visitors
                          self.realm.add(newChartrDate)
                      }
                  }
  
                  visitors = realm.objects(ChartCount.self)
              }
          }
  </code></pre>
  
  <p>And this to create the StartOfWeekDate</p>
  
  <pre><code>// Finds the start/end of the current week ----------------------------------------------- //
  extension Date {
      func startOfWeek(weekday: Int?) -&gt; Date {
          var cal = Calendar.current
          var component = cal.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)
          component.to12am()
          cal.firstWeekday = weekday ?? 1
          return cal.date(from: component)!
      }
  
      func endOfWeek(weekday: Int) -&gt; Date {
          let cal = Calendar.current
          var component = DateComponents()
          component.weekOfYear = 1
          component.day = -1
          component.to12pm()
          return cal.date(byAdding: component, to: startOfWeek(weekday: weekday))!
      }
  
      func monthDay() -&gt; String? {
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "MMM dd"
          return dateFormatter.string(from: self)
      }
  }
  internal extension DateComponents {
      mutating func to12am() {
          self.hour = 0 + 24
          self.minute = 0
          self.second = 0
      }
  
      mutating func to12pm(){
          self.hour = 0
          self.minute = 0
          self.second = 0
      }
  }// &lt;/end&gt; Finds the start/end of the current week ------------------------------------------ //
  </code></pre>
  
  <p>All I want to do is check the 'date' column of my ChartDate model to see if there is an object in it that contains the first day of this week (e.g. startOfWeekDate). </p>