dev-resources.site
for different kinds of informations.
Directly store value using "if expression" - Swift
Published at
12/4/2024
Categories
swift
ios
Author
annurdien
Author
9 person written this
annurdien
open
When we want to set a variable for a specific condition, this what we normally do:
let temperatureInCelsius = 25
let weatherAdvice: String
if temperatureInCelsius <= 0 {
weatherAdvice = "It's very cold. Consider wearing a scarf."
} else if temperatureInCelsius >= 30 {
weatherAdvice = "It's really warm. Don't forget to wear sunscreen."
} else {
weatherAdvice = "It's not that cold. Wear a T-shirt."
}
print(weatherAdvice)
// Prints "It's not that cold. Wear a T-shirt."
We can make it more cleaner using if expression
:
let temperatureInCelsius = 25
let weatherAdvice = if temperatureInCelsius <= 0 {
"It's very cold. Consider wearing a scarf."
} else if temperatureInCelsius >= 30 {
"It's really warm. Don't forget to wear sunscreen."
} else {
"It's not that cold. Wear a T-shirt."
}
print(weatherAdvice)
// Prints "It's not that cold. Wear a T-shirt."
Learn more:
swift Article's
30 articles in total
MVVM directory structure for larger project
read article
What Do All iOS Engineers Keep Forgetting?
read article
Mastering 4 way Infinite Scroll in SwiftUI!
read article
iOS Background Modes: A Quick Guide
read article
Debugging in Xcode: Tips to Save Your Time π οΈ
read article
I created a cool SwiftUI library!
read article
Optimizing iOS App Performance
read article
The Ultimate Guide to iOS Development: Closures (Part 7)
read article
Boost Your Appβs Performance with Lazy Stacks in SwiftUI
read article
The Ultimate Guide to iOS Development: Collections (Part 6)
read article
Access Control Levels in Swift
read article
Meet swift-api-client
read article
The Ultimate Guide to iOS Development: Functions (Part 5)
read article
Unlocking Face ID Integration: Boost Security and User Experience π
read article
Unlocking Business Growth with iOS Development Services
read article
MVC vs MVVM: A Real-Life iOS Interview Insight
read article
The Ultimate Guide to iOS Development: Control Flow (Part 4)
read article
Swift: A Journey into Open Source Excellence
read article
Object-Oriented Programming inΒ Swift
read article
A Drum machine for iOS
read article
The Ultimate Guide to iOS Development: Variables, Data Types, and Basic Operations in Swift (Part 3)
read article
The Ultimate Guide to iOS Development: From Programming Basics to Building Your First App (Part 2)
read article
Top 5 iOS App Templates to Kickstart Your Next Project
read article
The Ultimate Guide to iOS Development: From Programming Basics to Building Your First App (Part 1)
read article
Cosmos is hiring a senior iOS eng
read article
How To Add Multiple Modules In The Swift Package Manager
read article
Enhance Debugging in Swift with #file, #line, and #function
read article
Directly store value using "if expression" - Swift
currently reading
Day 3: Mull It Over | Advent of Code 2024 | Swift | δΈζ
read article
Property Wrappers in Swift: From Basics to Advanced Techniques
read article
Featured ones: