This question already has an answer here:
- Converting NSString to NSDate (and back again) 17 answers
I try to convert string to date
my method looks like this
func createDateFromString(string: String) -> NSDate {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
let date = dateFormatter.dateFromString(string)
return date!
}
But I have a runtime a error.
fatal error: unexpectedly found nil while unwrapping an Optional value
String is not empty :
what am I doing wrong ?