Hello people
I recently began my attempt at learning Swift using the Apple tutorial book and playgrounds. I have no experience with Swift or in programming, so it’s been a steep hill, but still, it’s been interesting.
However, I’ve now reached a point where I can’t seem to find the answers for an exercise in the Apple playground; the exercise – Counting Votes.
First issue: The calculation in my loop seems to be off.
the loop in question:
var yesVotes = [0]
var noVotes = [0]
for vote in shouldMascotChangeVotes {
if vote == true {
yesVotes += [1]
} else {
vote == false
noVotes += [1]
}
}
yesVotes.count
noVotes.count
The array supplied by Apple to the exercise only has 200 votes, yet my loop calculation returns a total of 202 votes. I can't see where the extra votes comes from?
Second issue:
according to the exercise, the next step is to write a function that takes two arguments, forIssue as a String and withVotes as Bool. The result of printResults should be “Should we change mascot? 54 yes, 23 no”.
So, my attempt at the function so far is thus:
func results(forIssue: String, withVotes: Bool) -> String {
for vote in withVotes {
if vote == true {
yesVotes += [1]
} else {
vote == false
noVotes += [1]
}
}
}
I'm pretty certain the function is wrong in a bunch of places and still not finished, but my question is primarily that I don't understand the error-message for the for vote in withVotes line. The message reads "Type 'Bool' does not conform to protocol 'Sequence'... Any explanation on this would be greatly appreciated!
Also, thank you very much for all the explanations in many other questions that have helped me in my attempts so far!
Cheers
(also, if this question is in the wrong forum, sorry about that)