I'm a beginner, started a couple of days ago, just doing it for fun, so maybe I'm wrong but seems to me there are at least 2 mistakes in Apple's Intro to App Development !
1 - in the Swift playground file 11_MakingDecisions
2 - in the iBook Intro to App Development with Swift Chapter 11
1 - Swift playground file > 11_MakingDecisions > Functions and Decisions
This is the code
func bandCanCarryGear(bandMemberCount: Int, gearWeight: Int) -> Bool {
let maximumTripCount = 2
let weightPerPerson = 50
let carryingCapacity = bandMemberCount * weightPerPerson * maximumTripCount
return gearWeight < carryingCapacity
}
if bandCanCarryGear(bandMemberCount: 5, gearWeight: 600) {
"Rock on."
} else {
"Everyone quits! Looks like you've got a solo show"
}
which, when bandMemberCount is set to 5, resolves to "Everyone quits! Looks like you've got a solo show".
So far so good.
But then the lesson finishes with
Now anyone reading the code should be able to understand what it’s doing. (It looks like you need to hire another drummer, or leave some speakers behind.)
But if you increase bandMemberCount to 6, you get the same message because gearWeight (i.e. 6 * 2 * 50) = carryingCapacity (not <), therefore the top function still returns false.
QED Adding ONE more drummer makes no difference. Either add TWO drummers or change this line
return gearWeight < carryingCapacity
to
return gearWeight <= carryingCapacity
2 - iBooks - Intro to App Development with Swift > Chapter 11, page 76 - Check your understanding Question 3 of 3
This is the code in a multiple choice question
let numbers = 100
if numbers > 99 {
print("What a smallish number!")
} else if numbers < 150 {
print("That's not so big.")
}
print("Goodbye.")
What will the code snippet print out? (4 choices)
A - "What a smallish number!"
B - "What a smallish number!" "Goodbye."
C - "What a smallish number!" "That's not so big." "Goodbye."
D - "That's not so big." "Goodbye."
They give the correct answer as D
I think the correct answer is B, and I've run the code online to check and it gives B.
The reason is that the if statement stops on the first true statement (100 > 99) and never gets to the second statement (100 < 150).
If I am correct on these two points, I'd appreciate someone more knowledgeable confirming. If I'm right, the multiple choice is a particularly bad mistake in a reference book as it seems to teach the opposite of what is true.
Also if Apple is reading this and are unaware of these errata and wish to reward me with an Apple Pencil bounty I will not insult their magnanimity by refusing 🙂Else, knowledge is its own reward 🙂