swiftui

SwiftUI declarative UI with state management

SwiftUI revolutionizes iOS development with declarative syntax where you describe what the UI should look like based on state. Views automatically update when state changes using property wrappers like @State, @Binding, and @ObservedObject. The @State

Custom SwiftUI view modifiers for reusability

View modifiers encapsulate reusable styling and behavior in SwiftUI. Creating custom modifiers keeps views clean and promotes consistency. I define modifiers by conforming to the ViewModifier protocol, implementing body(content:) that transforms the c

Navigation patterns with NavigationStack

SwiftUI's NavigationStack introduced in iOS 16 provides programmatic navigation with type-safe paths. I use NavigationPath to manage navigation state, enabling deep linking and state restoration. The navigationDestination modifier maps path values to

Dark mode support and adaptive colors

Dark mode provides low-light interface that reduces eye strain and saves battery on OLED displays. iOS automatically switches based on system settings or user preference. I use semantic colors like .label, .secondaryLabel, and .systemBackground that a

SwiftUI task modifiers and async lifecycle

SwiftUI's .task modifier handles async operations tied to view lifecycle. The task starts when the view appears and cancels automatically when it disappears, preventing memory leaks. I use .task for data fetching, subscriptions, and long-running opera

Image caching with NSCache and async loading

Loading images from URLs requires caching to avoid redundant network calls and improve performance. I create an image cache using NSCache which automatically evicts objects under memory pressure. The cache stores UIImage or Data keyed by URL. For asyn

SwiftUI PreferenceKey for child-to-parent communication

PreferenceKey enables child views to pass data up to ancestors, complementing the typical parent-to-child flow. I define a custom preference key by conforming to PreferenceKey protocol with a defaultValue and reduce method that combines multiple value

SwiftUI List with pull-to-refresh and infinite scroll

Lists are fundamental to iOS apps, displaying scrollable collections efficiently. SwiftUI's List or ScrollView with LazyVStack renders items on-demand. I add pull-to-refresh with the .refreshable modifier, calling async refresh logic. For infinite scr

Property wrappers for SwiftUI state

SwiftUI property wrappers manage state and data flow declaratively. @State creates mutable state owned by a view for simple values. @Binding creates two-way connections to pass state down the hierarchy without ownership. @ObservedObject watches extern

SwiftUI animations and transitions

SwiftUI makes animations declarative and automatic. The .animation() modifier animates state changes with built-in curves like .easeInOut, .spring(), or custom timing. Explicit animations use withAnimation {} blocks to scope which changes animate. Tra

SwiftUI custom shapes and paths

Custom shapes enable unique UI designs beyond standard views. Conforming to Shape protocol requires implementing path(in:) that returns a Path describing the geometry. I use path methods like move(to:), addLine(to:), addArc(), and addCurve() to draw c

SwiftUI GeometryReader for dynamic layouts

GeometryReader provides parent view size and coordinates, enabling dynamic layouts that adapt to available space. The reader passes a GeometryProxy with size and coordinate space info. I use it for responsive designs—calculate grid columns based on wi