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) Variables and Constants Constants

can help me i still get it by video from first to end can someone explain more simple

need help i don know how to say please someone explain to me

constants.swift
var str : string = "language"

let language : string = "Swift"

var greeting = str + language

3 Answers

Correct. But you can write it this way as well:

let language: String = "Swift"

It's just that you don't have to, as Swift can tell that you are assigning a String to the variable.

Re class/type, here's a quote from the Swift documentation: "A string is a series of characters, such as "hello, world" or "albatross". Swift strings are represented by the String type."

String is a type, so it needs to be capitalized, just as Bool and Int and Double do.

Classes you write are also types, so some folk use type and class pretty much as if they were synonyms, but that's not quite correct since in Swift as structs, enums and protocols are also types. Anyway, they all must be capitalized.

First, this line

let language : string = "Swift"

fails because String must be capitalized (it's a class). Also, you don't need to give the type (class) as Swift can infer it from the value you are assigning the constant.

Second, the challenge doesn't ask you to create a variable greeting.

So all you need is this:

let language = "Swift"

what is mean for (it's a class) is small letter?

so i just need write like this?

let language ="Swift"

can i follow you profile at treehouse?