[swift-users] DateFormatter crash on second usage (new instance) on Linux (swift 3.0.1)

Michael Bauer mcbauer08 at gmail.com
Wed Jan 25 17:53:07 CST 2017



> On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users at swift.org> wrote:
> 
> Hi
> 
> Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
> 
> 
> func dateConv(_ dateString: String) -> Date? {
>   let dateFormatter = DateFormatter()
>   dateFormatter.dateFormat = "MMM dd HH:mm"
>   dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
>   if let date = dateFormatter.date(from: dateString) {
>     print("Real date: \(date)" )
>     return date
>   }
>   return nil
> }
> 
> var date  = dateConv("Jan 25 20:10")
> var date2 = dateConv("Jan 25 20:11”)

Check out your parentheses. The last one is a right curly quote not the straight ascii quote that it should be.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170125/cb57f3e3/attachment.html>


More information about the swift-users mailing list