SwiftUI - Button Styles, View Modifiers, Animatable

This playground demonstrates key SwiftUI and Combine concepts including: Network requests using async/await and Combine MVVM architecture SwiftUI views and navigation Protocol-based networking JSON decoding struct SwiftUIView: View { @State private var range: ClosedRange = 0…5 @State var shakeNUmber: Int = 10 var body: some View { NavigationView { VStack { Button { withAnimation(.easeInOut(duration: 0.5)) { // Use a known animation let random = Int.random(in: 10…20) range = 0…random } } label: { Text(“Randomize”) } ....

February 4, 2025

SwiftUI - Preferences, PreferenceKey, AlignmentGuide, coordinateSpace, matchedGeometryEffect

SwiftUI provides several powerful mechanisms for layout control and view coordination. Let’s explore some key concepts: matchedGeometryEffect matchedGeometryEffect allows you to create smooth animations between views that share the same identity. This is particularly useful for transitions where you want elements to morph from one state to another. In the example below, we create a highlight effect that follows selected buttons: struct MatchedGeometryView: View { @Namespace var namespace let groupID = "highlight" var body: some View { VStack { Button("Sign Up") {} ....

February 4, 2025

SwiftUI and Combine Example

This playground demonstrates key SwiftUI and Combine concepts including: Network requests using async/await and Combine MVVM architecture SwiftUI views and navigation Protocol-based networking JSON decoding import Foundation import SwiftUI import PlaygroundSupport import Combine // MARK: - Networking // Protocol defining network operations protocol NetworkManaging { func fetch<T:Decodable>(url: String) throws -> T func uploadFile(url: String) } extension NetworkManaging { func uploadfile(url: String) { } } // MARK: - Models // Post model conforming to Decodable for JSON parsing and Identifiable for SwiftUI lists struct Post: Decodable, Identifiable { let id: Int let title: String } extension Post: Hashable { func hash(into hasher: inout Hasher) { hasher....

February 4, 2025