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:
https://www.dropbox.com/sh/f32breo0vkj5574/AAB9ui5E-x9OESRkjk40CxJba?dl=0

My Book: How I Became an iOS Developer:
https://gumroad.com/l/sean-allen-origin

Books, Hoodies, and other goodies:
seanallen.co/store

Check out my podcast, iOS Dev Discussions:
https://itunes.apple.com/us/podcast/ios-dev-discussions-sean-allen/id1426167395?mt=2

Paul Hudson of Hacking with Swift and I started a podcast called Swift Over Coffee:
https://itunes.apple.com/us/podcast/swift-over-coffee/id1435076502?mt=2

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

Paul Hudson’s Hacking With Swift:
https://gumroad.com/a/762098803

Learn Advanced Swift Here:
https://gumroad.com/a/656585843

Links to my Developer & YouTube Setup
https://www.amazon.com/shop/seanallen

Personal Links:

Swift News Hoodies & iPhone Case:
https://teespring.com/stores/sean-allen

Twitter:
https://twitter.com/seanallen_dev

Instagram:
@seanallen_dev

Patreon:
https://www.patreon.com/seanallen

Website:
https://seanallen.co

Comments

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: https://youtu.be/1hCwOIgjLBA

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

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


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

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles   Show Cars   Motorbikes   Scooters   Bicycles   Rims & Tires   Luxury BoatsFashion   Sunglasses   Luxury Watches   Luxury Purses   Jeans Wear   High Heels   Kinis Swimwear   Perfumes   Jewellery   Cosmetics   Shaving Helpers   Fashion Hats   Modeling TipsFooding   Chef Club   Fooding Helpers   Coktails & LiquorsSports   Sport Shoes   Fitness & Detox   Golf Gear   Racquets   Hiking & Trek Gear   Diving Equipment   Ski Gear   Snowboards   Surf Boards   Rollers & SkatesEntertainment   DIY Guides   Zik Instruments   Published Books   Music Albums   Cine Movies   Trading Helpers   Make Money   Fishing Equipment   Paintball Supplies   Trading Card Games   Telescopes   Knives   Vapes   GameplaysHigh Tech   Flat Screens   Tech Devices   Camera Lenses   Audio HiFi   Printers   USB Devices   PC Hardware   Network Gear   Cloud Servers   Software Helpers   Programmer Helpers   Mobile Apps   Hearing AidsHome   Home Furniture   Home Appliances   Tools Workshop   Beddings   Floor Layings   Barbecues   Aquarium Gear   Safe Boxes   Office Supplies   Security Locks   Cleaning ProductsKids   Baby Strollers   Child Car Seats   Remote ControlledTravel   Luggages & Bags   Airlines Seats   Hotel Rooms   Fun Trips   Cruise Ships   Mexico Tours