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

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

SOLID

SOLID: The First 5 Principles of Object Oriented Design | DigitalOcean #weblinks Dependency Inversion Principle Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions. The Dependency Inversion Principle is a software design principle that states that high-level modules should not depend on low-level modules. Instead, both should depend on abstractions. This allows for greater flexibility and maintainability of the code....

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

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