NSDate-TimeAgo icon indicating copy to clipboard operation
NSDate-TimeAgo copied to clipboard

Swift timeAgo returns empty string.

Open jacks205 opened this issue 9 years ago • 6 comments

I am calling timeAgo from NSDate and it returns an empty string.

if let validDate = lastUpdated{
    let dateText = validDate.timeAgo
    self.updatedLabel.text = dateText
    print(validDate.timeAgo)
}

I tried to debug the Swift extension and found it gets an empty string there.

screen shot 2015-09-28 at 3 16 46 pm

This is how I am creating my NSDate if it is important:

let dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSX"
if let date = dateFormatter.dateFromString(dateString) {
    // I get valid a NSDate object
}

jacks205 avatar Sep 28 '15 22:09 jacks205

Hi jack,

Did you import the .bundle folder into your project? It was also returning an empty string for me before I do it.

victtavares avatar Oct 02 '15 18:10 victtavares

No I just added the pod. That could be the issue.

jacks205 avatar Oct 05 '15 18:10 jacks205

Under Cocoapods and Swift you are likely using use_frameworks. The currently released version on Cocoapods uses the main bundle as the location for the resource bundle, which will be broken when frameworks are used.

This issue seems to be fixed in the most recent master branch, so as a workaround until it's released, try a git repo line in your Podfile

slangley avatar Nov 05 '15 20:11 slangley

@jacks205 is empty string issue resolved? As i am still getting it. Thanks

shafqat-muneer avatar Mar 10 '16 15:03 shafqat-muneer

@shafqat-muneer I'm not sure about the state of the pod, but I opted using this fuction someone put into a gist.

jacks205 avatar Mar 10 '16 18:03 jacks205

let dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC") dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSX" if let date = dateFormatter.dateFromString(dateString) { // I get valid a NSDate object }

khakha010 avatar Apr 08 '19 20:04 khakha010