The next topic in my series on iOS Interview questions explains unwrapping Optionals in Swift. This iOS interview question was asked in most almost all interviews. In this Swift tutorial I’ll explain if let, guard statements, optional chaining, and force unwrapping, using Xcode.
This is part of a series of videos about iOS interview questions in Swift. Check out the overview where I list and briefly discuss all the topics that are in this series:
https://youtu.be/56ZO6Gg68tw
Optional Chaining Apple Doc
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/OptionalChaining.html
Xcode Project Source Code:
https://www.dropbox.com/sh/rnx5gabo6s9ktt0/AAAr63-6HmSVMLq8KowRFxDJa?dl=0
Follow me on Twitter:
https://twitter.com/SeanA0400
Amazon Auto Links: No products found.
Thanks Sean! Great video. Just try to talk slower 🙂
i have already completed swift 4 documentation…………. now i want to start my demo projenct
plwase hellp me
Thanks. It’s clear understanding. You nailed it
Clear explanation !!
func yearAlbumReleased(name: String) -> Int? {
if name == “Taylor Swift” { return 2006 }
if name == “Fearless” { return 2008 }
if name == “Speak Now” { return 2010 }
if name == “Red” { return 2012 }
if name == “1989” { return 2014 }
return nil
}
How to use IF LET here ….?
optional map is another way
Thanks for clearing up guard statements, Sean. These are great videos and very easy to follow along with, but I’ll admit I had to turn the speed to 0.75 to keep up!
Clear and to the point!
Expecting more Thanks
i need advance level all tutorial
in line 10 you write if let number = optionalNumber
does it means that let nuber = optinalNumber is a bollean?
Hi Sean Allen
I am new to iOS. i want to send a soap request with xml data. i tired lot of examples . but didn’t work . could you help me.
I am developing swift Project. I have to pass Username & Password inputs as xml data (Username & Password are Params)
Thanks in advance
awesome! I think I finally get the difference between ways to unwrap, nice and concise. I think I’m even getting used to your delivery speed. Kinda starting to like it.
I watched so many videos about optionals, but this one is fantastic 😀 Thank you
Great Job @Sean! 🙂
Very nice and clean examples. Thumbs up!
Thanks. This is a quality tutorial. Keep up the good work!
Was never soo clear about all of these concepts. Thank you soo much. Great Job.
Thank you! I think i finally understand how to handle optionals.
Great Video! Thanks. One question though – do u know why all those objects in the library, like UIButton!, has to be declare as optionals?
How about when u declare variable like this: var number: Int!
this means: “I am sure 100% that number variable will have value?”
great tutorial
Here’s one: Let’s say I have a wrapper that contains a boolean called isHeader… How the hell I can write below code without force wrapper var and be conformed with lint good practices
if wrapper?.isHeader == nil || !(wrapper?.isHeader)! { return .zero }
return CGSize(10)
Tried something like
guard let myWrapper = wrapper, myWrapper.isHeader else { return .zero } but after got lint warning Unused Optional Binding Violation: Prefer `!= nil` over `let _ =` (unused_optional_binding)
Anu suggestion?
Great video, thank you for sharing!
Great tutorial. There is one more technique to unwrap an optional. Nil-Coalescing Operator: let a = b ?? c
Great video!
Questions about unwrapping optionals? Leave a comment and I’m happy to help!
How is the operator “??” called then?
Hi Can you please tell about the Database topics in real time implementation
Hi Sean! What monitor do you have? Thnx!
Thanks Sean, big fan of your tutorials 🙂
Great explanation
keep’em coming. I subbed
Force unwrapping you only want to do when you prototype stuff that is new to you in Playground.
helpful video thank you.
Great video! I just found your channel yesterday and have not stopped watching your videos since. They are extremely motivating. Keep it up! 😀
Just subscribed 🙂 Do more videos
thank you very good performance 🙂