func greetingLogic() -> String {
let date = NSDate()
let calendar = NSCalendar.current
let currentHour = calendar.component(.hour, from: date as Date)
let hourInt = Int(currentHour.description)!
let NEW_DAY = 0
let NOON = 12
let SUNSET = 18
let MIDNIGHT = 24
var greetingText = "Hello" // Default greeting text
if hourInt >= NEW_DAY && hourInt <= NOON {
greetingText = "Good Morning"
}
else if hourInt > NOON && hourInt <= SUNSET {
greetingText = "Good Afternoon"
}
else if hourInt > SUNSET && hourInt <= MIDNIGHT {
greetingText = "Good Evening"
}
return greetingText
}
Last active
February 27, 2021 11:03
-
-
Save WrathChaos/17c4c761faff355cdb8b6d8d3ae2f2a8 to your computer and use it in GitHub Desktop.
iOS / Swift 5 How to make a dynamic greeting message? Article: https://freakycoder.com/ios-notes-51-how-to-set-a-time-based-dynamic-greeting-message-swift-5-6c629632ceb5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment