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 Swift 2.0 Enumerations and Optionals Introduction to Optionals Initializing Optional Values

Welby Obeng
Welby Obeng
20,340 Points

I don't understand this task

Pasan Premaratne I don't understand this task

You said to create a failable initializer that accepts a dictionary as input an initializes all the stored properties. How can I do that if all the properties are constants? Am I missing something

optionals.swift
struct Book {
    let title: String
    let author: String
    let price: String?
    let pubDate: String?

    }

4 Answers

Michael Hulet
Michael Hulet
47,842 Points

A constant's value doesn't change once it's initialized. In other words, it's legal to do something like this:

class Example{

  let constant: String

  init(value: String){
    self.constant = value
  }
}

Create a constant named favDessert and assign to it a string containing your favorite dessert. Remember the syntax for a string is some text enclosed with two double quotes. Pro Tip: Dessert is spelled with two s'

Jason Hess
Jason Hess
4,789 Points

so I'm new to swift and trying to pass this challenge, here's my code:

let = "favDessert";

var str = "cookies";

Do I ned to include the semi-colons?

I've also tried this syntax, what am I doing wrong here.

let str = "favDessert"

let str = "cookies"

Any help would be great. Thanks in advance

Here is the correct answer: let favDessert = "Candy" (Note: You can use anything instead of "Candy")

stephenallison
stephenallison
8,559 Points

let favoriteDessert = "input fav here" is the proper syntax. The question itself can be tricky.