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 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,913 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.