Beginner Swift Tutorial – Ternary Operator

In today’s beginner Swift tutorial I’ll be explaining how to use the conditional ternary operator. This is a good way to clean up your simple if/else statements in your code. We can replace that if/else statement with one line of code. In this video, I’ll show you how. This tutorial is in Swift 4.2 and Xcode 10.

Source Code:

My Book: How I Became an iOS Developer:

Books, Hoodies, and other goodies:

Check out my podcast, iOS Dev Discussions:

Paul Hudson of Hacking with Swift and I started a podcast called Swift Over Coffee:

Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):

Paul Hudson’s Hacking With Swift:

Learn Advanced Swift Here:

Links to my Developer & YouTube Setup

Personal Links:

Swift News Hoodies & iPhone Case:






Govind Suryawanshi says:

Nice explanation with giving common example….!

Oğuz Akankan says:

Please more Swift beginner tuts thanks

khaled al hammod says:

3 tutorials in one day, thank you man for your hard work. I have to say your channel is one of my favorites, and my story is quiet smeller to yours as well, actually, I am following you from Syria, that’s like on the other half of earth ! and I am saying that because its always good to know that your efforts are benefiting people you didn’t even imagine they follow you or listen to what you make .
I hope soon I will be as good a programmer as you. thanks again, great tutorials.

Donat Hmm says:

Great beginner tutorial

chrispy_wa says:

Love it. Very useful indeed.

Ali Zuberi says:

Great video

Sean Allen says:

Recommended Next Video – Beginner Programmatic UI. No Storyboard:

emiN roblack says:

Daym man, you are on fire! 🙂
Between you and Paul i don’t think i have enough time left to watch “Only in Russia” type of clips XD

Konrad My says:

Just bought my ticket for iOS Con! Feeling like an iPhone in the App Store! So please stay healthy, don’t burn out and bring some Swift News hoodies, Sean! And have you thought about printing some red beard logo stickers, like the podcast? Those would be fire!

vamsi krishna says:

Back to back within no time

Semper Phoenix says:

let isSeanOnARoll = videosToday >= 2 ? true : false

Donat Hmm says:

Can you make a video about how to handle internet connection in my application I always ask this myself always.

Yogesh Jaiswal says:

Another video in one day!!

Andrea Grumpeenlate says:

Awesome, it makes it so much easier to digest those notions in such short videos. Thanks a lot!

Dave Borchard says:

Sean, You should build an app that has a table view pointing to all your videos. You could have different sections for news and training. You could have a search box to look up specific topics or keywords.

While, I appreciate your free videos, it would also give you ac opportunity to put hopefully low cost training on the app as an in-app purchase. You could also put a forum right in the app, and you could promote what you do in the app. I’m surprised that you don’t already have a Sean Allen app!

Wesley Teunissen says:

Loving the amount of vids your pushing out man! Great stuff

David Wu says:

Great tutorial. Thank you for the good work.

Ankit Gupta says:

How to parse “Any” and “AnyObject” type from JSON response using swift Codable Protocol?

Alex Tsv says:

Hey , Sean ! Thanks for amazing video ! I’m am swift newbie and building my first application . I want to know your opinion .
My main screen in application is collection view controller . There are like 6 cells , and I have detail view controller showing up with some info filled , when users presses on collection view cell . I’m just wondering , what’s better : create 6 VC’s on storyboard and use segues from specific cell to specific controller , or
use only one vc , and pass data via segue to show different information , depending on cell pressed ? Actually it’s quite confusing for me , and I don’t won’t all this mess with vc files containing only few lines of code ( Yes, I saw your video about base vc…) .
PS: detail view controller screens are pretty much the same. All the difference is text , that they are containing .

Sorry for my English , I’m not native .

Fernando Borges Paul says:

Amazing video Sean! I love the fact you have your videos ordered by levels of difficulty 😀 Regards from Mexico mate!

Arjun Bemarkar says:

For the is even wouldnt it be better just to say isEven = number%2 == 0

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!