QOTD ⚡Are optionals getting you down? Let me know! They were definitely hard for me when I first started!👇 Kick start your own app with my free 7 Day App Action Plan ➡️ bit.ly/7dplan
Phew!!! Thank you for the Optionals lesson. I have had a hard time when building apps small apps. I have in all the case chosen to force unwrap and not bother to perform the checks, bad move on my part. Had to go back to basics and learn this topic from scratch!!! Now I see the importance, and thank you very much
Another great video. Just could not grasp what optionals were or why someone would use them before watching this. Now I do. Hope you continue to post great videos like this!
Great video as usual Chris. For the newbies, you could also use guard statements as an alternative to avoid the nasty if/let nests of doom. Guards can be extremely useful when you need your object to have a value. For example.. let post = BlogPost() post.title = "Hey your title is here!" func foo() { guard let actualTitle = post.title else { print("No title here buddy") return } print(actualTitle) } foo() **console prints Hey your title is here!**
Thanks for the feedback and showing others Riccy! I'm still getting used to incorporating guard into my own coding habits. Here's a good article for anyone who's interested in learning more about when to use guard vs if: www.natashatherobot.com/swift-when-to-use-guard-vs-if/
thank you man for your effort, you style is very simple to understand, I hope you keep up the good work and complete this series, help us beginners learn how to code thanks a lot man, may Allah reward you for that good deed :)
Started learning swift 2 days back, I had no clue what optionals meant and searched every where but couldn't get a neat explanation as yours. Every video of yours is clear and nice..... please do some videos about tableviews and Api's.:-)
Thanks for putting out content like this! I was hoping you would explain how to use the var author:Person? within optional binding...but that's alright, challenge accepted, I'll try to figure it out.
We can always make one full video about this! We are really trying to keep the videos as short as possible while still covering the essential. (because a 20 to 30 minutes, people usually start to lose focus). Stay tuned for more on RUclips and if you cannot wait, we have more covered on www.codewithchris.com -Adrien
I need to be able make a good apps by 2020 March 10th and it was March 10 2019 when I started thanks to that I got a MacBook Pro with touchbar though and I needed a person to teach me and when I found you I was amazed by how good you though you should work as a MIT professor for computer science
Chris, you forgot one more way to deal with optionals, which stumbled upon while following along."Your a \(you.somevalue ?? "Default value")" assuming that you is a class and somevalue is set to either a string or nil
Question, is the data in a class public/global and changeable from outside the class object? You were able to set post.title = yo from outside object without sending a message to the object's member function (in this case there was none), this seems very dangerous. Great video series, thanks for sharing and keep up the great work
Hello, if since the author inside the class blogpost is another class then just use another dot (.) for example blog1=blogpost() blog1.author.name to get the name of the author - Francis
The only thing i found confusing was that to check if the variable was nil or not you didn't unwrap it first. You did need to force unwrap it with the exclamation point to use it as a string for the print statement. How can you check the assignment in the if-let statement before unwrapping it first, and how can you know if it is nil or not nil without unwrapping it first. I still don't understand why the box metaphor doesn't work in that case...
My understanding is in the example where we test for nil if post.title != nil { print(post.title! + " salut!!") } we are forcing it to unwrap, meaning that even though we know that it can never execute *print(post.title! + " salut!!")*, since we checked if it was equal to nil first, the code will always operate fine. However, in if let actualTitle = post.title { print(actualTitle + " salut") } we actually are unwrapping it, just in a different way. When we write *if let actualTitle = post.title*, we are saying that we have no idea what is inside post.title. So, when we use *if let actualTitle = post.title*, we set actualTitle to what ever post.title is, and the if statement does not execute in the instance of actualTitle being set to nil. Thus, we have unwrapped it to see what was inside, which was either nothing, in which case we ignore the print command, or we get something, and then we execute the print command. Also, remember that nil is a fancy way of saying nothingness, and means nearly the exact same thing as the word null, which is used in other programing languages instead of nil. Again, this is my understanding of what is going on. Here is some example code with comments that might help. //Unwrap and test if it is not nil if let actualTitle = post.title{ //if so, we have something useful. print("Something awesome is here!") } else { //otherwise, we have nothing, as the condition fails, and execute the following code. print("Ah, man. The box was empty.") } I hope this helps.
If all the videos on our RUclips page aren't helping enough, drop us a message on our Community Group. We will help you right there. bit.ly/CWCCommunity -Adrien
Hi Chris About the object "name" in the class Person you didn't explain how to use it. I have tried to use it without success until i realized it was necessary to make the object name as 'optional'. At next time please explain things like this more clearly
Raghavan Ramaswamy because if you look in the middle of the screen right above the text ( //Optional Binding ) He gave “post.title” the meaning “yo” It’s not in any curly brackets either so it’s almost like a new code on it’s own
when i tried downloading Xcode it said Xcode can’t be installed on “Macintosh HD” because OS X version 10.11.5 or later is required. i tried updating but says no update available, help please
I think Swift is really stupid language. They are overcomplicating concepts just so that it differs from robust languages like C++/Java. In those languages you choose initialise or not a variable in a simple readable way. Swift is a overkill in my opinion. But the tutorials are amazing. Thanks bro :D
QOTD ⚡Are optionals getting you down? Let me know! They were definitely hard for me when I first started!👇 Kick start your own app with my free 7 Day App Action Plan ➡️ bit.ly/7dplan
You're one of the few people who actually explain everything they're doing. Thank you.
Thank you! Really trying to guide the best we can!
-Adrien
Your gift box analogy is great! I'll think of optionals this way from now on. Keep up the good work Chris!
Awesome! Thanks for watching! :)
You are the one who made it clear for me how optionals work and what they are for. Thank you for that! Great work.
Thank you!!!!!
@AdrienVillez
You explained optionals in a way that's clear and easy to understand! Thank you for using the analogy about a box and unwrapping the present.
So thankful for your kind words, Nirdhar! We'll keep on working hard to produce more high-quality lessons just for you guys! -Arthur
Wow! Your explanation about optionals is the best - short and easy-to-understand! Thank you very much, Chris!
Thanks Julia! I love hearing that!
Phew!!! Thank you for the Optionals lesson.
I have had a hard time when building apps small apps.
I have in all the case chosen to force unwrap and not bother to perform the checks, bad move on my part.
Had to go back to basics and learn this topic from scratch!!!
Now I see the importance, and thank you very much
Swift is everything about Optionals! Watch out!
@AdrienVillez
I wonder how anyone could give unlike for this video. It is so well explained that it looks like a good adventure movie
:) First time i heard that analogy, but i really like it!
Another great video. Just could not grasp what optionals were or why someone would use them before watching this. Now I do. Hope you continue to post great videos like this!
I will as long as you keep watching :)
Great video as usual Chris. For the newbies, you could also use guard statements as an alternative to avoid the nasty if/let nests of doom. Guards can be extremely useful when you need your object to have a value. For example..
let post = BlogPost()
post.title = "Hey your title is here!"
func foo() {
guard let actualTitle = post.title else {
print("No title here buddy")
return
}
print(actualTitle)
}
foo()
**console prints Hey your title is here!**
Thanks for the feedback and showing others Riccy! I'm still getting used to incorporating guard into my own coding habits. Here's a good article for anyone who's interested in learning more about when to use guard vs if: www.natashatherobot.com/swift-when-to-use-guard-vs-if/
Of course, keep up the great work!
thank you man for your effort, you style is very simple to understand, I hope you keep up the good work and complete this series, help us beginners learn how to code
thanks a lot man, may Allah reward you for that good deed :)
Great video series! really helpful for someone who doesn't have much time to dedicate in learning how to code
Started learning swift 2 days back, I had no clue what optionals meant and searched every where but couldn't get a neat explanation as yours. Every video of yours is clear and nice..... please do some videos about tableviews and Api's.:-)
Thanks Raj! Your suggestion is recorded and I do intend to cover those! Thanks!
Thank Chris. I like the way you teach. It cleared all my doubts..
Thanks! Clear and easy to understand as usual!
Thanks for learning with me!
I been watching every video you made for Swift
Dedicated follower! 🔥
@AdrienVillez
Awesome. Very clear explained. Thanks Chris
Wow Burden of this optional is clear now. Now i can force unwrapp my idea to creat app. hahah! Thanks Chris
Hey Kapil, thanks for watching as always!
Thanks for putting out content like this! I was hoping you would explain how to use the var author:Person? within optional binding...but that's alright, challenge accepted, I'll try to figure it out.
We can always make one full video about this! We are really trying to keep the videos as short as possible while still covering the essential. (because a 20 to 30 minutes, people usually start to lose focus).
Stay tuned for more on RUclips and if you cannot wait, we have more covered on www.codewithchris.com
-Adrien
Good explanation on what optionals are and how to unwrap them, although I'm still uncertain of what instances I would actually use them.
Thank you for your tutorials! it helps a lot :)
I need to be able make a good apps by 2020 March 10th and it was March 10 2019 when I started thanks to that I got a MacBook Pro with touchbar though and I needed a person to teach me and when I found you I was amazed by how good you though you should work as a MIT professor for computer science
Thank you for the kind comment! Glad we can help you get started in iOS! Good luck for your project! See you in 2020!
@AdrienVillez
Best of luck for you! Are you planning to create good apps for Apple Dev Academy entrance or WWDC?
great video thanks!
at 6:08 The box analogy made me realize that with optionals, it becomes Schroedinger's Variable!
Bless you!
@AdrienVillez
so good dude! man killin it bro
haha thanks!
Needed this....thanks!
OMG THANK YOU for this video!
Sure! Looks like we made something click and now things make sense! 😉
@AdrienVillez
Great video Chris!
Love your username and great first tutorial! Thanks for watching!
CodeWithChris no problem, thanks again!
Thank you, great video!
Thanks for learning with me Daniel!
Chris, you forgot one more way to deal with optionals, which stumbled upon while following along."Your a \(you.somevalue ?? "Default value")" assuming that you is a class and somevalue is set to either a string or nil
Thanks, Chris
I made a suggestion on some other channel I think to post a video on optionals and his greatness answered lol
That's awesome :) What a coincidence!
thank you Chris you're awesome
You're awesome too for learning with me haha :)
Question, is the data in a class public/global and changeable from outside the class object? You were able to set post.title = yo from outside object without sending a message to the object's member function (in this case there was none), this seems very dangerous. Great video series, thanks for sharing and keep up the great work
How to unwarp the property author that is of data type Person? I am first time coder so, apologies for asking stupid question.
Hello, if since the author inside the class blogpost is another class then just use another dot (.)
for example blog1=blogpost()
blog1.author.name to get the name of the author
- Francis
Thank you!!
The only thing i found confusing was that to check if the variable was nil or not you didn't unwrap it first. You did need to force unwrap it with the exclamation point to use it as a string for the print statement. How can you check the assignment in the if-let statement before unwrapping it first, and how can you know if it is nil or not nil without unwrapping it first. I still don't understand why the box metaphor doesn't work in that case...
My understanding is in the example where we test for nil
if post.title != nil {
print(post.title! + " salut!!")
}
we are forcing it to unwrap, meaning that even though we know that it can never execute *print(post.title! + " salut!!")*, since we checked if it was equal to nil first, the code will always operate fine. However, in
if let actualTitle = post.title
{
print(actualTitle + " salut")
}
we actually are unwrapping it, just in a different way. When we write *if let actualTitle = post.title*, we are saying that we have no idea what is inside post.title. So, when we use *if let actualTitle = post.title*, we set actualTitle to what ever post.title is, and the if statement does not execute in the instance of actualTitle being set to nil. Thus, we have unwrapped it to see what was inside, which was either nothing, in which case we ignore the print command, or we get something, and then we execute the print command.
Also, remember that nil is a fancy way of saying nothingness, and means nearly the exact same thing as the word null, which is used in other programing languages instead of nil.
Again, this is my understanding of what is going on.
Here is some example code with comments that might help.
//Unwrap and test if it is not nil
if let actualTitle = post.title{
//if so, we have something useful.
print("Something awesome is here!")
}
else { //otherwise, we have nothing, as the condition fails, and execute the following code.
print("Ah, man. The box was empty.")
}
I hope this helps.
a great video for beginner like me ^^
Are you teacher? If not, you are like them! Fine pedagogy!
Thank you!
so for //testing for nil at 14:47, why cant you just have one if statement and one else statement? why two if statements?
This is correct! You can use else for the other branch of the IF Statement.
This video was mostly to show how to do it using == or !=.
Lol i'm understanding optionals by thinking of Schroedinger's cat; you don't know whether it's dead inside or alive without opening it
Wasn't aware about this, so I Googled!
Here for the curious: en.wikipedia.org/wiki/Schr%C3%B6dinger%27s_cat
@AdrienVillez
Thank you
Thanks for watching Gabriel!
Hello @CodeWithChris we have a control on swift language can you help us please ?
If all the videos on our RUclips page aren't helping enough, drop us a message on our Community Group. We will help you right there. bit.ly/CWCCommunity
-Adrien
Hi Chris
About the object "name" in the class Person you didn't explain how to use it.
I have tried to use it without success until i realized it was necessary to make the object name as 'optional'.
At next time please explain things like this more clearly
Hey Nir, thanks for your feedback! I have an upcoming video on optionals that explains the concepts more clearly!
i'm waiting to see it, you do a fantastic job here.
thank you :)
@13:11 when you print out post.title! why does the print statement say Optional("yo")
Raghavan Ramaswamy because he wrote the code
post.title=yo
30guarino why is there the word optional there before it
Raghavan Ramaswamy because if you look in the middle of the screen right above the text ( //Optional Binding )
He gave “post.title” the meaning “yo”
It’s not in any curly brackets either so it’s almost like a new code on it’s own
Raghavan Ramaswamy make no mistake about I’m only 3 days in to this foreign syntax ....But repetition is the mother of all Skills
Hey, just curious…
Have you done any other programming language before swift? If so, what?
Just wonderin….🤗🤗🤔
I'll have to ask Chris, haha! :-) -Arthur
Awesome :)
Nice! Thanks for learning with me!
hello , I want to share this in China,if you allow. can you gei me a zip about all zhe videos.your classes are so nice! LOVE
give
I'm aware RUclips is not accessible in China. I will have to look for alternatives.
gooooood
very veryy godddddddd
Thanks Daniel! I appreciate it!
Hi. Thanks for videos. Why I getting? "error: Optionals.playground:5:9: error: expected pattern
var = name ""
^"
If we could see the code, that would be helpful. Can you post a screenshot in our #CodeCrew group?
bit.ly/CWCCommunity
Thanks!
@AdrienVillez
when i tried downloading Xcode it said Xcode can’t be installed on “Macintosh HD” because OS X version 10.11.5 or later is required. i tried updating but says no update available, help please
The cheat sheet are not working
PLEASE HELP ME WITH THIS.
I TRIED MANY TIMES.
gift box ))
Xmas every day with Swift!
@AdrienVillez
I gave a empty gift box to a friend and we broke up because I said the empty gift box was his birthday present
Well, he got a box at least!
@AdrienVillez
ttttttttthhhhhhhhhhhhhhhhhink uuuuuuuuuuuuuuuuu
Youuuuuuuuuuuuuuuuuuuuuuuuuur Wellllllcccoooooooooooooooooooommme!
- Adrien
We are in bts sn in aurillac please HELP UUUUUUS
I think Swift is really stupid language. They are overcomplicating concepts just so that it differs from robust languages like C++/Java. In those languages you choose initialise or not a variable in a simple readable way. Swift is a overkill in my opinion. But the tutorials are amazing. Thanks bro :D
Thank you very much!
Thank you for learning with us!
@AdrienVillez
Awesome :)
Hey Hassan, thanks for watching and commenting!