Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Closures in Swift 2 Building Standard Library Functions Map

Getting the wrong date in Formatted array


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.