Property Wrappers in Swift

Property wrappers add a layer of separation between code that manages how a property is stored and the code that defines a property. A property wrapper is a type that wraps a property, adding additional behavior or validation. They were introduced in Swift 5.1. Key Components @propertyWrapper Attribute: Marks a type as a property wrapper wrappedValue: The underlying value being wrapped projectedValue (optional): Additional functionality exposed via $ prefix Common Use Cases Property wrappers are commonly used for:...

February 4, 2025

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

Learning/DesignPatterns

Design Patterns implemented in Swift 5.0 A short cheat-sheet with Xcode 10.2 Playground (Design-Patterns.playground.zip). 🇨🇳中文版 👷 Project started by: @nsmeme (Oktawian Chojnacki) 👷 中文版由 @binglogo (棒棒彬) 整理翻译。 🚀 How to generate README, Playground and zip from source: GENERATE.md print("Welcome!") Table of Contents Behavioral Creational Structural 🐝 Chain Of Responsibility 🌰 Abstract Factory 🔌 Adapter 👫 Command 👷 Builder 🌉 Bridge 🎶 Interpreter 🏭 Factory Method 🌿 Composite 🍫 Iterator 🔂 Monostate 🍧 Decorator 💐 Mediator 🃏 Prototype 🎁 Façade 💾 Memento 💍 Singleton 🍃 Flyweight 👓 Observer ☔ Protection Proxy 🐉 State 🍬 Virtual Proxy 💡 Strategy 🏃 Visitor 📝 Template Method Behavioral In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns....

January 15, 2025

programming/iOS/api-clients

Swift API Client Strategy This document outlines a comprehensive strategy for creating an API client in Swift using async/await. The approach is designed to be modular, reusable, and easy to extend for various API endpoints. Components Endpoint Protocol: Defines the base URL and path for each API endpoint. NetworkManaging Protocol: Defines the contract for network operations. NetworkManager Class: Implements the NetworkManaging protocol to handle network requests. Error Handling: Manages errors that may occur during network requests....

January 15, 2025

Understanding Swift's Codable Protocol

Swift’s Codable protocol is a powerful feature that simplifies the process of encoding and decoding data between Swift types and external representations like JSON. This guide covers everything you need to know about working with Codable. What is Codable? Codable is a type alias that combines two protocols: typealias Codable = Encodable & Decodable Encodable: Allows converting Swift types to external formats (e.g., JSON) Decodable: Allows converting external formats back into Swift types Basic Usage The simplest way to use Codable is with types that have Codable-compatible properties:...

January 15, 2025

Learning/Architecture

iOS Architecture Analytics Architecture MVVM The MVVM (Model-View-ViewModel) architecture is a design pattern that is used to structure the code in iOS apps. It is similar to the MVC (Model-View-Controller) architecture, but it introduces a new component called the ViewModel. The ViewModel is responsible for exposing data to the View and facilitating communication between the Model and the View. One of the main benefits of using MVVM is that it helps to separate the business logic of an app from the user interface, which makes it easier to develop and maintain the app over time....

January 22, 2023

content/interviewing

Uber prep DSA SwiftSearchTrie/SwiftSearchTree.swift at main · wvabrinskas/SwiftSearchTrie #weblinks SimpleApiClient/SimpleApiClient.swift at master · wvabrinskas/SimpleApiClient #weblinks Genetic/Array+Extensions.swift at master · wvabrinskas/Genetic #weblinks Algorithms Recent HashMap with extra tasks + tests, Design photos news feed + API Code up a function that meets specific criteria, analyze runtime and optimize. Mobile systems design, algorithms, iOS live coding and behavioral with Hiring manager There was a behavioral interview, an iOS coding challenge, a data structures & algorithms whiteboard Interview, and iOS app architecture / design Interview....

January 11, 2023

programming/iOS

Apple Challenge 1 /* A FunkyNotificationCenter object that broadcasts events within a program. Code that wants to observe notification events registers a closure via the addObserver(:for:block:) method. Code that sends notifications uses the post(notificationName:) method. Each closure that was registered for that notification name should be called. */ import Foundation class FunkyNotificationCenter { typealias notifBlock = () -> Void var entries: [String: [notifBlock]] = [:] init() // mynotif, block1, block2 /// Post a notification with the given name....

January 11, 2023