Intro to App Development with Swift - Lesson 13

Dear all,


I have recently started learning to code with the 'Intro to App Development with Swift' book available on the iBooks Store.

I have a couple of questions as I am frequently stuck due to what is, in my opinion, a lack of clarity in the questions.

Sometimes I manage to get around it after a couple of days of thinking and sometimes I just cannot (and often because there were errors in the playgrounds provided).


Here are my questions:

1) are there provided solutions for the 'Intro to App Development with Swift' curriculum? I know that something is available for the next step, 'App Development with Swift' but I need this first one, at least to be able, after 20-30 minutes of brain crunching, to go look at a hint to let my brain make the next step.


2) if there are not, could somebody help me with Lesson 13? It is the 'QuestionAnswerer' playground, page 'Dealing with Cases'. It explained me this:


let question = "WHERE ARE THE COOKIES?"

let lowerQuestion = question.lowercased()

lowerQuestion.hasPrefix("where")


...where I learned how to check for lower cases and to change an existing string so that it became lowercase (I later learned on my own that also a .uppercased() method existed). Then the playground asks me this:


| Experiment:

Rewrite the function below to work with aNy cAsE of QueStiOn TeXT, so you get a correct answer in the example:


func responseTo(question: String) -> String {


if question.hasPrefix("hello") {

return "Why, hello there"

} else {

return "That really depends"

}

}


___

The issue I find with these kind of questions is that it asks you to rewrite the function but doesn't give you any possible hint.

I tried to add the lines above, I tried with a nested if ... if ... if ... else ... statement but it told me that strings cannot be converted to bool.

I would understand if you didnt want to write me the solution but I would appreciate a hint on where to go, then I will go.

Just open me the door and I will cross it 🙂


Thank you all

M

Replies

>1) are there provided solutions for the 'Intro to App Development with Swift' curriculum?


Did you check the 'Resources' link located in the Intro? Otherwise, note that in some examples, such as lesson 5, it's all in the chapter - see the MLT links below.

Hi

for your question number 2:


just use the code below after the { of the function


func responseTo(question: String) -> String {        //after this line
     
        let lowerQuestion = question.lowercased()    //use this code

Thank you, ommshi! This works for me. I just changed "lowerQuestion" to "question" instance to avoid error:


func responseTo(question: String) -> String {


let question = question.lowercased()




At first, I tried to add lowrcased() property to part where function was called like this:


responseTo(question: "Hello!").lowercased()


but this didn't work.