Programming in Swift: Fundamentals · Challenge: Optionals |

This is a companion discussion topic for the original entry at

Edited: I downloaded all-in-one source code from first lesson and optional challenge is including in that file.

I am enjoying this series. Chris is an excellent instructor and wears a very cool shirt!

There are no challenge files for optionals. could anyone help me with the link?

Very minor, but fyi, the constant is not actually provided as stated in the exercise instruction for Challenge 1 in Optionals.

Might bet worth adding the download file here like the others to avoid confusion.

Am enjoying the course, thanks!

Hi there! The video team has just informed me that they’ve corrected the playground for this challenge to include the missing constant. Thanks again!

Hi I see the beginning as a blank, no challenge

@corax You can download both the starter and final playgrounds using the Download Materials button. Please let me know if you have any other questions or issues about the whole thing. Thank you!

How far does the string comparison go, in challenge 3 my name is “Mike” and the result is false. Given “Matt Galloway” is “Ma” and I’m “Mi” I think it stops there, but how far does it go down the string? If I only entered “Mike” and was comparing to “Mike Smith” what happens?

Hey @mimaguire,

The answer is that Swift goes “as far as it needs to”.

So in your example, if you are comparing “Mike” and “Mike Smith”, Swift keeps going down the string and finds a space after “Mike” in the second string, whereas there’s “nothing” after the first “Mike”. In this case, “anything” is greater than “nothing”, so “Mike Smith” should be greater than just “Mike”.

If you dive into the internal algorithm that Swift uses for string comparison, I believe you’ll find that Swift actually parses both strings in their entirety - but it uses some advanced sorting to do this as efficiently as possible.

Just a note that the Optional Challenge has not be been fixed.

For example: “Challenge 1: You’ve been provided with a constant below, hasAllergies, which has been set to true.”

No constant has been provided and will be very confusing to new users. This is the same for the previous challenge (Logical Operators) as well.

Hey @sedawk : This course is being updated for Swift 5.5 as I type this, so I’ll mention that to the course updater (Catie Catterwaul). Thanks for the note!

Thank-you Chris. Great courses by the way. I especially like how they are updated so your Swift and SwiftUI content is up-to-date.

Happy to bring you the latest updates, @sedawk ! Glad you’re enjoying them.

I am really enjoying the Programming in Swift: Fundamentals and love Chris as an instructor! Like Chris I wear Hawaiian shirts all of the time!

So I have a question, as I came from primarily C# background, but have done Delphi, C, C++… so in C# you are taught to initialize ALL variables, whether or not you know what value it will be later… either with Nil, (or Null, suddenly I forget which) or “” on strings… So why would you not do that in swift, then if the variable becomes known later on, you are good to go? I am just not sure why this is not done in Swift, there must be something that is not yet clear… Thank you!