If you've written Swift for even a short time, you've already used Generics —whether you realized it or not. Types like Array , Dictionary , Set , and even Optional are all built using generics. Generics are one of Swift's most powerful language features because they help us write reusable, type-safe, and maintainable code . Let's understand them step by step. Why Do We Need Generics? Imagine writing separate functions for every data type. func printInt(_ value: Int) { ... } func printString(_ value: String) { ... } func printDouble(_ value: Double) { ... } The logic is identical, but we're repeating code simply because the data types are different. One option is to use Any . func printValue(_ value: Any) { print(value) } While this works, it comes with a drawback—you lose compile-time type safety and often need runtime type casting ( as? or as! ). Generics solve this problem by allowing us to write code once and reuse it with different data types without sacr...
Recently I published a countdown app . At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !? But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option) 1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...