Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Closures in Swift 2 Building Standard Library Functions Map

Getting the wrong date in Formatted array

Hi,

I use xCode 8 and swift 3 and therefore I need to make a couple of changes to det the code to compile correctly.

struct Formatter {
    static let formatter = DateFormatter()

    static func dateFromString(dateString: String) -> NSDate? {
        formatter.dateFormat = "d MMM yyyy"
        return formatter.date(from: dateString) as NSDate?
    }
}

let dateStrings = ["10 Oct 1988", "11 Jan 1947", "28 Mar 2002"]

let dates = dateStrings.map { Formatter.dateFromString(dateString: $0) }

I think this is correct? The problem I get is that the array of NSDate? Types is wrong I always get a day short

[Optional(1988-10-09 23:00:00 +0000), Optional(1947-01-10 23:00:00 +0000), Optional(2002-03-27 23:00:00 +0000)]

I am in Sweden so my local settings is a little different than the one in the video. But as you can se I get 9-okt-1988 instead of 10-okt-1988, and it’s the same error on the other dates as well

Derick Derick
Derick Derick
7,653 Points

I have the same problem. Please help.