Shaideru

All things iOS & Swift

Converting NSDate to String with Core Data [Swift]

I was working on Data Core today, I just figured out fetching NSDate data type value from data core and displaying it as a String data type.

Here is the date formatter function snippet

func dateFormatter(date: NSDate) -> String {
var dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "EEE, MMM d, yyyy - h:mm a"
return dateFormatter.stringFromDate(date)
}

And these are the lines of codes on fetching and converting using the function above

var dateToStringValue = data.valueForKeyPath("date") as NSDate!
cell.dateCell?.text = dateFormatter(dateToStringValue) as String?

2 Discussions on
“Converting NSDate to String with Core Data [Swift]”

Leave A Comment

Your email address will not be published.