This question already has an answer here:
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 ?
You should just remove
.SSS
fromdateFormat
and implicit unwrapping to avoid fatal error (function should return optional value).Try with