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 Swift Basics (retired) Types Numbers

it keeps saying that my " 'let' declarations require an initializer expression" does anybody know what this means?

Please read above

numbers.swift
let title: String
  println("A Dance with Dragons")

thank you so very much!

thank you so very much!

thank you so very much!

thank you so very much!

3 Answers

let title: String
title = "A Dance with Dragons"
println(title)
Robin Nilsson
Robin Nilsson
3,783 Points

Or rather:

let title: String = "A Dance with Dragons"
println(title)

That will work too. :)

Since you declared 'title' as a constant, meaning a value fixed in memory, it must be given a value, else the concept of a constant declaration has no meaning. The error is basically Swift saying, "Why did you tell me to store a constant value in my memory without telling me what it is?"

thank you so very much

what you have done above is declared a constant (using the "let" keyword) given it a name (title) and said that it is of the type String but you have not given it any value. if you wrote let title: String = "A String" then the compiler would not show that error message and the value of title would be A string

I appreciate your support on this question!