title: Can't assign to Int from Date extension's function
body: <p>I need to get how many days there are from two dates, so I've used this code I've found online</p>
  
  <pre><code>extension Date {
  
      func years(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.year], from: sinceDate, to: self).year
      }
  
      func months(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.month], from: sinceDate, to: self).month
      }
  
      func days(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.day], from: sinceDate, to: self).day
      }
  
      func hours(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.hour], from: sinceDate, to: self).hour
      }
  
      func minutes(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.minute], from: sinceDate, to: self).minute
      }
  
      func seconds(_ sinceDate: Date) -&gt; Int? {
          return Calendar.current.dateComponents([.second], from: sinceDate, to: self).second
      }  
  }
  </code></pre>
  
  <p>which is an extension of the Date class.</p>
  
  <p>I'm facing a problem when using those functions, I have this function</p>
  
  <pre><code>func countDays() {
          if let daysLeft = Date.days(targetDate) {
              self.daysLeft = daysLeft
          }
      }
  </code></pre>
  
  <p>but Xcode tells me that </p>
  
  <p><em>Initializer for conditional binding must have Optional type, not '(Date) -> Int?'</em></p>
  
  <p>So, then I tried this function</p>
  
  <pre><code>func countDays() {
          let daysLeft = Date.days(targetDate)
          self.daysLeft = daysLeft
      }
  </code></pre>
  
  <p>Still Xcode tells me that </p>
  
  <p><em>Cannot assign value of type '(Date) -> Int?' to type 'Int'</em></p>
  
  <p>I've tried building the project a few times because I thought it could be an error but the issue remains.</p>
  
  <p>Can anyone point out what could be the issue here? Thanks in advance!</p>
  
  <p>EDIT: I've already tried to force unwrap the returned values like this</p>
  
  <pre><code>func years(_ sinceDate: Date) -&gt; Int {
          return Calendar.current.dateComponents([.year], from: sinceDate, to: self).year!
      }
  </code></pre>
  
  <p>Still Xcode tells me the same thing
  <em>Cannot assign value of type '(Date) -> Int' to type 'Int'</em></p>