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 Build a Weather App with Swift (Retired) Data Modeling With Structures Customizing Dates

Andrew Bernard
Andrew Bernard
23,262 Points

Having Trouble with Build a Weather App in Swift - Part 2 Data Modeling With Structures

I am having a little trouble following along with what this question is asking... http://teamtreehouse.com/library/build-a-weather-app-with-swift/data-modeling-with-structures/customizing-dates

    import Foundation
    let secondsSinceBirth = NSTimeInterval(1200000000)
    var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
    var dateFormatter = NSDateFormatter()

Here is where I am starting. Thanks

5 Answers

zachkeith
zachkeith
10,719 Points

You need to set the dateFormatter time and date styles that you can set the string.

Something like:

dateFormatter.timeStyle = .Short
dateFormatter.DateStyle = .Medium

Now you can set the string:

var stringDate = dateFormatter.stringFromDate(dateOfBirth)

yes thanks Marquay. Edited that now

Marquay Smith
Marquay Smith
7,865 Points

Probably a typo but it should be: var stringDate = dateFormatter*.stringFromDate*(dateOfBirth)

Andrew Bernard
Andrew Bernard
23,262 Points

Thanks that helped a ton!

Had a few little changes but that was the general form. Thanks

What's wrong with my code??

import Foundation
let secondsSinceBirth = NSTimeInterval(1200000000)
var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
var dateFormatter = NSDateFormatter()

dateFormatter.timeStyle =.Short dateFormatter.DateStyle =.Medium

var stringDate = dateFormatter.stringFormDate(dateOfBirth)
Eric Whittaker
Eric Whittaker
2,974 Points

Watch around 6:00 in the "Cleaning Up Our Date" video to find the problem with your syntax

Sergio Cisneros
Sergio Cisneros
13,078 Points

My Code looks pretty much just like yours. Ive been trying different things and can't get it. Were you able to figure this out?

Andrew Bernard
Andrew Bernard
23,262 Points

Look at your .Short and .Medium and see if that is the correct .notation for those Styles.

thomas howard
thomas howard
17,572 Points

Thanks for all your insight. I'm sorry to say I was entirely confused, until I realized that I had spelled 'style' as 'sytle'. darn it.