Skip to main content

Posts

WWDC26: What's New in SwiftUI — 10 Features Every iOS Developer Should Know

  SwiftUI continues to mature with every WWDC, and this year is no exception. At WWDC26, Apple introduced several improvements that make SwiftUI faster, more flexible, and easier to use across Apple platforms. Some updates are visual, while others solve long-standing pain points like image caching, compile-time performance, and custom interactions. Here are the 10 biggest SwiftUI updates from WWDC26 that every iOS developer should know. 1. Automatic Adoption of the New Liquid Glass Design Apps built with Xcode 27 automatically adopt Apple's refreshed Liquid Glass appearance. Apple has also introduced new APIs to better integrate with the updated design language: appearsActive environment value Prominent tabs Toolbar overflow menus Auto-minimizing navigation bars while scrolling The best part? Most apps require little or no code changes to benefit from the new appearance. 2. iPhone Apps Are Now Resizable SwiftUI now supports resizable iPhone apps, making layouts much more adaptable...

Swift Generics Explained – A Practical Guide

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...

Swift Optionals under the hood

In Swift, an Optional is a way to say “this value might be there, or it might be missing.” We use ? to show that a value is optional, like: var name: String? But what is really happening behind the scenes? What an Optional Really Is Inside Swift, an Optional is just a simple enum with two cases: enum Optional<Wrapped> { case none // no value case some(Wrapped) // has a value } That’s all an Optional is! So when you write: var age: Int? Swift actually thinks: var age: Optional<Int> The ? is only a shortcut for us. Why Optionals Feel Special Even though Optionals are simple, Swift gives them extra features: if let and guard let value ?? defaultValue value! for force unwrap a?.b?.c for optional chaining These special features work only with Swift’s built-in Optional. How Swift Stores Optionals Swift stores Optionals in a smart way: Many Optionals take no extra memory compared to the normal value. Swift uses unused bits or adds a small...

Understanding MVVM + Clean Architecture in SwiftUI

When building an iOS app, it's important to organize your code in a way that keeps things clean, testable, and easy to maintain. One of the best ways to do that is by combining MVVM (Model–View–ViewModel) with Clean Architecture . 1. Presentation Layer — The SwiftUI Frontline This is where your app interacts with the user . In SwiftUI, the View and ViewModel live in this layer. View (SwiftUI View): These are your UI screens — for example, ContentView , LoginView , or ProfileView . SwiftUI Views are simple and reactive. They observe data and automatically update the UI when something changes. struct ContentView: View { @StateObject var viewModel = ContentViewModel() var body: some View { VStack { if viewModel.isLoading { ProgressView() } else { List(viewModel.items) { item in Text(item.title) } } } .onAppear { viewModel.fetchItems() } ...

Understanding Task { }, Task.detached { }, and Task { @MainActor in … } in Swift Concurrency

Swift’s concurrency model introduced a cleaner and safer alternative to GCD. But with this came a common confusion: When should I use Task {} , Task.detached {} , and Task { @MainActor in ... } ? If you’ve ever wondered which one to pick, this article will clear it up with simple explanations and real-world guidance.

Understanding Copy-on-Write in Swift & Why It Matters in SwiftUI

  When you start building apps in Swift or SwiftUI, you’ll often hear the term “Copy-on-Write” — or CoW for short. It sounds fancy, but the idea is actually very simple and smart. Let’s break it down. Swift uses value types like struct , Array , Dictionary , and String . Normally, when you copy a value type, you’d expect it to create a new copy in memory. But copying big data every time can be slow and wasteful. So Swift uses a trick called Copy-on-Write — it pretends to copy the data, but it doesn’t actually do it until you change something. var numbers = [1, 2, 3] var moreNumbers = numbers  // No real copy yet! moreNumbers.append(4)      // Now Swift makes a real copy here. At first, both variables share the same data. Only when you modify moreNumbers, Swift creates a separate copy so that the original numbers stays safe. This is how Swift gives you safe, independent data but still keeps things fast and memory-friendly. How It Connects to SwiftUI Now he...

Benefits of Swift Testing over XCTest

If you’ve been building apps in Swift for a while, you’ve probably spent some time writing tests with  XCTest . It’s been the default testing framework on Apple platforms for years, and while it does the job, it often feels… a little clunky. Now enter Swift Testing — a newer, more modern testing framework that’s part of the Swift open-source project. The difference is immediately noticeable. Writing tests with Swift Testing feels like writing Swift code, not fighting a bunch of boilerplate. Here are some of the reasons why many developers are starting to prefer Swift Testing over XCTest: 1. The Syntax Just Flows Better In XCTest, you’re constantly reaching for XCTAssertEqual , XCTAssertTrue , XCTAssertNil , and so on. Each one has its own function, and you need to remember which is which. In Swift Testing, you simply use #expect with plain Swift expressions: #expect(result == 42) Compare that to: XCTAssertEqual(result, 42) Not a huge difference in one line, but when you multiply ...

Popular posts from this blog

Animating label text update - choosing a better way

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...

Cached Async Image in SwiftUI

 SwiftUI’s AsyncImage is handy, but every time your view appears, it refetches the image—leading to flicker, delays, and unnecessary network use. What if you could fetch once, then reuse instantly? That's exactly what the Cached Async Image  delivers: a memory-powered caching layer that keeps SwiftUI image loading smooth, snappy, and resilient. First a simple in-memory cache without disk persistence. This will be thread-safe and auto-purges under memory pressure. A Singleton wrapping NSCache for URL → UIImage caching as follows : final class ImageCache {   static let shared = ImageCache()   private init() {}   private let cache = NSCache<NSURL, UIImage>()   func image(for url: URL) -> UIImage? {     cache.object(forKey: url as NSURL)   }   func insertImage(_ image: UIImage?, for url: URL) {     guard let image else { return }     cache.setObject(image, forKey: url as NSURL)   }   func clearAll() { ...

Implementing autocompletion OTP field in iOS

Long waiting is over. !!  iOS 12 brings Autofill for OTP text field which is close to Android provided a decade back. Previously in iOS we used to toggle between OTP text screen and message inbox.  Which was hard to remember and time consuming resulting a bad user experience. Personally, I have been asked from the client/customer couple of times to implement autocompletion for OTP field and took me a lot of time to convey that it is not possible in iOS. Why Autofill was not possible previously?  We all know that Apple gives at most care for user privacy. When we see iOS architecture, each individual app is like a separate island. There is no inter-app bridge between apps (exception for Keychain and URLSchemes APIs which gives very limited scope). Thus we cannot read message content from inbox. Where to start Autofilling? First of all, the target SMS need to have the OTP Code with prefix string "Code" or "Passcode"on its message content. Beware of OTP c...

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...