title: swift nsobject class how to return value
body: <p>i am new in swift how to create common class and return string Here is my code where i do mistake Please help me. This is my nsobject common class </p>
  
  <pre><code>import UIKit
  
      class DayCount: NSObject {
  
          func doSomething(getDate:String)  -&gt; String   {
  
  
              let start = "2015­06­01"
  
              let end = NSDate()
  
              let dateFormatter = NSDateFormatter()
  
              dateFormatter.dateFormat = "yyyy­MM­dd"
  
              var endDateSting:String = dateFormatter.stringFromDate(end)
  
              let startDate:NSDate = dateFormatter.dateFromString(start)!
  
              let endDate:NSDate = dateFormatter.dateFromString(endDateSting)!
  
              let cal = NSCalendar.currentCalendar()
  
              let unit:NSCalendarUnit = .CalendarUnitDay
  
              let components = cal.components(unit, fromDate: startDate, toDate:
  
                  endDate, options: nil)
  
              println(components)
              let date:String? = (self.timeAgoSinceDate(startDate, numericDates: Bool()))
  
              println(date)
  
              return date!
  
  
              }
  
          func timeAgoSinceDate(date:NSDate, numericDates:Bool) -&gt; String {
              let calendar = NSCalendar.currentCalendar()
  
              let unitFlags = NSCalendarUnit.CalendarUnitMinute |
  
                  NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay |
  
                  NSCalendarUnit.CalendarUnitWeekOfYear
  
              NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear |
  
                  NSCalendarUnit.CalendarUnitSecond
  
              let now = NSDate()
  
              let earliest = now.earlierDate(date)
  
              let latest = (earliest == now) ? date : now
  
              let components:NSDateComponents = calendar.components(unitFlags,
  
                  fromDate: earliest, toDate: latest, options: nil)
  
              if (components.year &gt;= 2) {
  
              } else if (components.year &gt;= 1){
  
              } else if (components.month &gt;= 2) {
  
              } else if (components.month &gt;= 1){
  
              } else if (components.weekOfYear &gt;= 2) {
  
              } else if (components.weekOfYear &gt;= 1){
  
              } else if (components.day &gt;= 2) {
  
              } else if (components.day &gt;= 1){
  
              } else if (components.hour &gt;= 2) {
  
              } else if (components.hour &gt;= 1){
  
                  return "\(components.year) years ago"
  
                  if (numericDates){
  
                      return "1 year ago"
  
                  } else {
  
                      return "Last year"
  
                  }
  
                  return "\(components.month) months ago"
  
                  if (numericDates){
  
                      return "1 month ago"
  
                  } else {
  
                      return "Last month"
  
                  }
  
                  return "\(components.weekOfYear) weeks ago"
  
                  if (numericDates){
  
                      return "1 week ago"
  
                  } else {
  
                      return "Last week"
  
                  }
  
                  return "\(components.day) days ago"
  
                  if (numericDates){
  
                      return "1 day ago"
  
                  } else {
  
                      return "Yesterday"
  
                  }
  
                  return "\(components.hour) hours ago"
  
                  if (numericDates){
  
                      return "1 hour ago"
  
                  } else {
  
                      return "An hour ago"
  
                  }
  
              } else if (components.minute &gt;= 2) {
  
                  return "\(components.minute) minutes ago"
  
              } else if (components.minute &gt;= 1){
  
                  if (numericDates){
  
                      return "1 minute ago"
  
                  } else {
  
                      return "A minute ago"
  
                  }
  
              } else if (components.second &gt;= 3) {
  
                  return "\(components.second) seconds ago"
  
              } else {
  
                  return "Just now"
  
              }
              return ""
          }
  
  
  
  
  
      }
  </code></pre>
  
  <p>and my view controller i have get this string like this but its return always error </p>
  
  <pre><code>let getdate = (DayCount.doSomething("sdfsdfsd")) 
          println("date===== \(getdate)")
  </code></pre>
  
  <p>The error is "(string)-> string is not convertible to DayCount"
  i have also Try this </p>
  
  <pre><code>let getdate:String = (DayCount.doSomething("sdfsdfsd"))
          println("date===== \(getdate)")
  </code></pre>
  
  <p>But it always return me error please help me where i do mistake </p>