Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Added solutions for the 3 optional challenges at the end of the project:
I also included example of how to use a for-loop to solve Challenge 1.
I felt this was important because most Codecademy learners -- even those who know other languages or have completed
the entire Learn Swift course -- would have trouble using a for-loop for Challenge 1 due to the nature of Swift's sets.
Reason
For anyone coming from another language or trying to implement what they learned from previous lessons, it makes sense to try using a
for
loop in Challenge 1.However, if you try to do it based on previous examples of
for
loops in the curriculum, it won't work as expected.Sets in Swift are value types and cannot be subscripted by their index the way arrays can.
This presents unique issues when trying to loop through a set of sets to perform manipulations on those sets.
I tried explaining this to a user in the Forums here and giving examples here, but quite frankly, this is probably too advanced for many of the learners to understand.
Rather than overwhelm learners when they ask about it on the forums, I think it might just be better to include these examples in the official sample solution. That way, if they get stuck they can see the easier solution as well as an example that uses the
for
loop.