Single Articles
Best Practicesβ
π΄ There Are 2 Ways to Violate 'S' in SOLIDβ
This article delves into the complexities of the Single Responsibility Principle (SRP) in the context of iOS development. Using a case study of a TransactionCellView
in a table view, it demonstrates how the addition of a button that alters the cell's layout based on specific conditions can lead to the violation of SRP. The article highlights the importance of avoiding the creation of "God objects" and over-abstraction, advocating for a refactor that moves decision-making logic out of the cell and into a more appropriate architectural layer. This ensures that each component retains a single responsibility, making the codebase more maintainable and scalable.
Details
URL: π There Are 2 Ways to Violate 'S' in SOLID
Published: April 30, 2021
Authors: Isaac Weisberg
Tags:
SOLID principles
, Single Responsibility Principle
, iOS development
, Swift
, software architecture
Key Pointsβ
- The article highlights two distinct ways in which the Single Responsibility Principle (SRP) can be violated in iOS development.
- The case study involves a
TransactionCellView
where the addition of a button based on conditional logic introduces multiple responsibilities within the cell. - The solution proposed involves refactoring to move decision-making logic out of the cell to ensure SRP compliance and maintain a clean architecture.
Summary of Contentsβ
- Introduction: Overview of the importance of SOLID principles in interviews and development.
- Case Study: Analysis of the
TransactionCellView
and how it violates SRP. - Problem Analysis: Discussion on the problems of having a single class handling multiple responsibilities.
- Solution: Detailed refactor proposal to restore SRP by moving logic out of the cell and into a dedicated layer.
Additional Resourcesβ
- π SOLID Principles Explained: A comprehensive guide to SOLID principles in software development.
- π Refactoring Techniques: Tips and techniques for effective code refactoring.
- π iOS Architecture Patterns: An overview of different architecture patterns used in iOS development.
π΅ Writing Good Unit Testsβ
This article by Chris Mash, published on Dev Genius, delves into the principles of writing effective unit tests in software development. It highlights the importance of having "good" unit tests that validate code behavior accurately, ensuring the reliability of your codebase during refactoring or updates. The article also explores Test Driven Development (TDD) as a method to foster better unit testing practices.
Details
URL: π https://blog.devgenius.io/writing-good-unit-tests-2158be9ee82d
Published: October 17, 2023
Authors: Chris Mash
Tags:
unit-testing
, software-development
, TDD
, iOS
Key Pointsβ
- Importance of Good Unit Tests: Good unit tests ensure that the code behaves as expected by isolating the subject under test and providing meaningful coverage.
- Examples of Poor vs. Improved Tests: The article offers concrete examples of how to improve test cases, making them more likely to catch issues.
- Test Driven Development (TDD): TDD is highlighted as a strategy to write better tests by integrating testing into the development process from the start.
Summary of Contentsβ
- Characteristics of Good Unit Tests: Discusses what makes a unit test effective, emphasizing the need for tests to validate behavior in detail and isolation.
- Examples of Poor vs. Improved Tests: Provides side-by-side comparisons of poor and improved test cases, showing how to refine tests to detect more issues.
- Test Driven Development (TDD): Explains the TDD process, offering practical advice on adopting it to write tests that enhance code quality and maintainability.
- Summary: Recaps the importance of early and isolated testing, and the value of good unit tests beyond mere code coverage.
Additional Resourcesβ
- π TDD Manifesto katas: Exercises to practice TDD techniques.
- π Kata-log katas: Additional katas to enhance TDD skills.
π΄ The Advanced Guide to UserDefaults in Swiftβ
This blog post provides an in-depth exploration of UserDefaults in Swift, particularly with the enhancements introduced in Swift 5. The article guides readers on effectively using UserDefaults for small data storage and delves into its internal structure and performance considerations. It also covers advanced topics like designing type-safe key-value storage using property wrappers and observing changes in UserDefaults.
Details
URL: π https://www.vadimbulavin.com/advanced-guide-to-userdefaults-in-swift/
Published: December 9, 2019
Authors: Vadim Bulavin
Tags:
Swift
, iOS
, UserDefaults
, Swift 5
, Property Wrappers
Key Pointsβ
- UserDefaults Overview: Understand the use of UserDefaults for storing small data and the types of data it supports.
- Internal Structure: Explore how UserDefaults are stored as .plist files and the implications of this structure on performance.
- Advanced Implementation: Learn how to create type-safe key-value storage using property wrappers in Swift.
- Observing Changes: Implement mechanisms for observing changes in UserDefaults values using Key-Value Observing (KVO).
Summary of Contentsβ
- Introduction: A brief overview of the evolution of UserDefaults in the context of Swift's development.
- UserDefaults Overview: Detailed discussion on what kind of data should be stored in UserDefaults and its internal implementation.
- Key-Value Storage Implementation: Step-by-step guide to implementing type-safe key-value storage using property wrappers.
- Observing UserDefaults: Techniques to observe changes in UserDefaults values, enhancing app responsiveness and data integrity.
- Conclusion: A recap of key insights about using UserDefaults effectively in modern Swift applications.
Additional Resourcesβ
- π The Complete Guide to Property Wrappers in Swift 5: A comprehensive guide to understanding and using property wrappers in Swift.
- π swift-corelibs-foundation: Explore the foundation source code for a deeper understanding of UserDefaults internals.
π΅ Writing Effective Release Notes: A Guide for Developersβ
Effective communication with your app's customers is essential. While many companies settle for generic phrases like "Bug fixes and performance improvements" in their release notes, writing great release notes doesn't need to be hard. Well-crafted release notes not only engage your users but also show your dedication to continually improving the app.
Details
URL: π https://blog.eliperkins.com/great-release-notes
Published: 2024-09-01
Authors: Eli Perkins
Tags:
release-notes
, app-updates
, customer-engagement
Key Pointsβ
- Writing release notes should focus on the customer rather than the company.
- Clear and consistent communication in release notes builds excitement and informs users of important changes.
- Avoid generic phrases; instead, highlight the benefits and outcomes of updates for the user.
Summary of Contentsβ
-
Importance of Great Release Notes: Release notes are a direct line of communication with your users. Properly crafted notes can enhance user engagement and show that you value their experience.
-
Guidelines for Writing Release Notes:
- Naming & Capitalization: Follow consistent rules for naming and capitalizing features.
- Tone and Tense: Use an active voice, avoid unnecessary words like "now," and focus on the user's experience.
- What's New: Emphasize the outcomes and behavior changes brought by new features.
- Bug Fixes: Be concise, front-load the fixes, and focus on how the fixes affect the user.
-
Handling No User-Facing Changes: When no user-facing updates are available, it's okay to reuse previous release notes, especially for ongoing features. This keeps the communication relevant and consistent.
Additional Resourcesβ
- π GitHub's Brand Content Guidelines: Follow these guidelines for consistent naming and capitalization.
- π GitHub Voice & Tone Guidelines: Ensure your release notes align with the overall brand voice.
π΅ Adapter Design Pattern in iOSβ
The Adapter Design Pattern is a structural design pattern that enables objects with incompatible interfaces to collaborate by using an intermediary known as the Adapter. This pattern is highly valuable in iOS development, especially when integrating third-party libraries, adapting legacy code, or bridging different frameworks.
Details
URL: π https://blog.stackademic.com/adapter-design-pattern-in-ios-9e008ec29414
Published: 2023-11-07
Authors: Stackademic
Tags:
design-patterns
, swift
, ios-development
, architecture
, adapter-pattern
Key Pointsβ
- Definition: Allows incompatible interfaces to work together via a wrapper object.
- Core Components: Target, Adapter, Adaptee, and Client.
- Use Cases: Integrating third-party libraries, simplifying complex interfaces, and bridging frameworks.
- Advantages: Enhances modularity, reusability, and separation of concerns in code.
- Disadvantages: May increase complexity and dependency.
Summary of Contentsβ
- Introduction: Overview of the Adapter Pattern and its significance in iOS.
- Core Components Explained: Details of the pattern's four components (Target, Adapter, Adaptee, and Client).
- Examples:
- General Scenarios: Printed photographs to digital, train systems with different engines.
- iOS Specific: Wrapping third-party libraries, adapting APIs.
- Step-by-Step Implementation in Swift:
- Creating the Target interface.
- Implementing the Adaptee.
- Designing the Adapter.
- Using the Adapter in the Client.
- Advantages and Disadvantages: A balanced view of the pattern's trade-offs.
π΅ Facade Design Pattern in iOSβ
The Facade Design Pattern is a structural design pattern that provides a unified interface to a set of interfaces in a subsystem, simplifying the interaction with complex systems. In iOS development, it is often used to streamline access to subsystems like network, database, and view layers.
Details
URL: π https://medium.com/@omar.saibaa/facade-design-pattern-in-ios-52138dd70e46
Published: 2023-11-01
Authors: Omar Saibaa
Tags:
design-patterns
, swift
, ios-development
, facade-pattern
, architecture
Key Pointsβ
- Definition: Provides a simplified interface to complex subsystems.
- Use Cases: Frequently used in iOS apps for simplifying access to network layers, database interactions, or view components.
- Advantages: Simplifies client code, decouples interfaces, reduces complexity, and improves performance through abstraction and caching.
- Disadvantages: Can introduce additional complexity, abstraction penalties, and reduced flexibility in some cases.
Summary of Contentsβ
- Introduction: Overview of the Facade Pattern and its role in simplifying subsystems.
- Examples: Conceptual and real-world scenarios, such as:
- Restaurant menu as a façade for complex kitchen operations.
- Unified access to banking app subsystems for checking balances, transferring money, and deposits.
- Simplifying interactions in e-commerce apps like Amazon.
- Unified interfaces for Facebook-like apps managing network, database, and view layers.
- Implementation Steps: A step-by-step guide to identifying subsystems, defining simplified interfaces, and creating facade classes to delegate requests.
- Code Examples: Example implementations demonstrating the benefits of the pattern in various contexts.
- Advantages and Disadvantages: Highlights the trade-offs when using this pattern.
π΅ Flyweight Design Pattern in iOSβ
The Flyweight Design Pattern is a structural design pattern focused on reducing memory usage by sharing intrinsic states among multiple objects. This approach minimizes redundancy and optimizes resource management in applications.
Details
URL: π https://thekrazyjames.medium.com/flyweight-design-pattern-in-ios-e5666433cd08
Published: 2024-05-11
Authors: The Krazy James
Tags:
design-patterns
, swift
, ios-development
, flyweight-pattern
, memory-optimization
Key Pointsβ
- Definition: Reduces memory usage by sharing intrinsic (immutable) states among objects.
- Intrinsic State: Immutable properties like birthdate or nationality.
- Extrinsic State: Mutable properties like expiration date or address.
- Advantages: Saves memory usage by eliminating redundancy.
- Common Mistakes: Avoid multiple instances of the same intrinsic state; use a factory or singleton to enforce uniqueness.
Summary of Contentsβ
- Introduction: Overview of the Flyweight Pattern and its relevance in optimizing memory usage.
- Core Concepts: Explanation of intrinsic and extrinsic states with examples from a driverβs license and passport system.
- Implementation: A detailed breakdown of how to separate intrinsic and extrinsic states in Swift, with code examples.
- Common Mistakes: Highlights pitfalls such as duplicating intrinsic states and suggests solutions like factories or singletons.
- Conclusion: Discusses the patternβs utility in scenarios like gaming, where shared textures reduce memory consumption.
Here is the blog post formatted strictly according to the blog_post.md template:
π΅ Composite Design Pattern in iOSβ
The Composite Design Pattern is a structural design pattern that allows the composition of objects into tree structures to represent part-whole hierarchies. This pattern simplifies client code by allowing uniform treatment of individual and composite objects.
Details
URL: π Original Blog Post
Published: [YYYY-MM-DD]
Authors: Abdulahd 1996
Tags:
design-patterns
, swift
, ios-development
, composite-pattern
, architecture
Key Pointsβ
- Definition: Represents part-whole hierarchies, enabling clients to treat individual objects and composites uniformly.
- Use Cases: Commonly used in file systems, GUI hierarchies, and analytics tracking in iOS.
- Advantages: Promotes scalability, abstraction, and separation of concerns.
- Real-World Examples: File systems, event tracking with multiple analytics services.
Summary of Contentsβ
- Introduction: Explanation of the Composite Pattern and its role in managing hierarchies.
- Example Implementation:
Component
: The protocol defining the interface for bothLeaf
andComposite
objects.Leaf
: Simple objects likeTextFile
andImageFile
.Composite
: Complex objects likeFolder
aggregating both files and subfolders.
- Real-World iOS Use Case: Refactoring tightly coupled event tracking into a scalable design using
EventTracker
protocol andCompositeTracker
. - Code Examples: Step-by-step implementation in Swift for hierarchical object management.
- Advantages: Improves scalability, decouples client code, adheres to SOLID principles, and simplifies testing.
π΅ SwiftUI MVVM-C: A Real-World Guideβ
This article explores the implementation of the Model-View-ViewModel-Coordinator (MVVM-C) pattern in SwiftUI with a detailed, practical example. MVVM-C combines SwiftUIβs declarative syntax with a structured architectural approach, enabling scalable and maintainable app development.
Details
Authors: Swift and Beyond
Tags:
swiftui
, mvvm-c
, ios-development
, app-architecture
, navigation
Key Pointsβ
- Definition: MVVM-C is an architectural pattern that separates concerns into Models, Views, ViewModels, and Coordinators to manage complex navigation flows.
- Advantages:
- Simplifies navigation flows.
- Improves modularity, scalability, and maintainability.
- Ensures separation of concerns.
Summary of Contentsβ
- Introduction: Brief overview of the MVVM-C pattern and its importance in SwiftUI.
- Coordinator: Central navigation hub managing the navigation stack with
pushPage()
andclearNavigationStack()
. - ViewModels: Protocol-driven, reactive logic connecting the UI to the Coordinator.
- Views: Declarative SwiftUI components leveraging
@ObservedObject
for state-driven UI updates. - Gender Entry Example: Demonstrates modular design using reusable components like
TextComponent
andButtonComponentView
. - Code Walkthrough: Full implementation of a SwiftUI app using MVVM-C, including reusable styles and navigation customization.
UML Class Diagramβ
Helpful Linksβ
π΅ How to Modularize a Monolithic iOS Appβ
This blog post outlines a structured approach to transitioning from a monolithic iOS application to a modular architecture. By leveraging the principles of layered architecture and dependency inversion, it explains how to organize code into distinct modules for improved maintainability, scalability, and efficiency.
Details
URL: π https://vbat.dev/how-to-modularize-monolith-ios-app
Video: π Watch Here
Published: 2024-05-12
Authors: Vitaly Batrakov
Tags:
iOS Development
, Modular Architecture
, Dependency Injection
, Layered Architecture
Key Pointsβ
- Modular Architecture:
- Divides an app into Core, Feature, and Composition Root layers.
- Promotes separation of concerns and loose coupling.
- Dependency Direction Rule: Dependencies can flow upwards but not downwards.
- Steps to Modularize:
- Begin by identifying and extracting shared functionalities into the Core Layer.
- Modularize feature-specific code into isolated Feature Modules.
- Use the Composition Root to manage dependency injection and object graph assembly.
- Best Practices:
- Avoid circular dependencies by inverting dependencies using protocols.
- Minimize direct dependencies between modules within the same layer.
Summary of Contentsβ
- From Monolith to Modularization:
- Overview of monolithic and layered architectures.
- Introduction to dependency direction rules and the layered modular architecture.
- Core Layer:
- Contains shared functionalities like networking, logging, UI components, and analytics.
- Operates independently of other core modules.
- Feature Layer:
- Encapsulates feature-specific logic, UI, and data handling.
- Encourages independent development and reusability.
- Composition Root:
- Centralized location for dependency injection and assembling object graphs.
- Facilitates flexibility and maintainability.
- Common Dependency Scenarios:
- Handling dependencies across modules using dependency inversion.
- Strategies for managing upward, downward, and lateral dependencies.
Additional Resourcesβ
- π Modular App Example on GitHub: Explore a simple implementation of modular architecture.
- π Dependency Injection Guide: Learn about DI patterns in iOS.
- π Introducing the Composition Root Pattern: Insights into the composition root approach.
SwiftUIβ
π΅ Double Optional Bindings or Something idkβ
This article explores a SwiftUI pattern involving double optionals, used in a project to manage the state of a sheet that either creates a new item or edits an existing one. By using an optional of an optional type, the code can signal whether to show the sheet and whether the sheet is in creation or editing mode.
Details
URL: π https://phlippieb.dev/posts/double-optional-bindings/
Published: June 25, 2024
Authors: Phlippie Bosman
Tags:
Swift
, SwiftUI
, Optional
, State Management
Key Pointsβ
- Double Optionals in SwiftUI: The article introduces a pattern where an optional of an optional type is used to control both the visibility and mode (create or edit) of a SwiftUI sheet.
- Use Case: This pattern is particularly useful in scenarios where a view needs to switch between creating a new item and editing an existing one.
- SwiftUI Integration: The pattern is integrated into SwiftUI using the
.sheet(item:)
modifier, which automatically presents a view when the bound state is non-nil.
Summary of Contentsβ
- Introduction: The post begins by explaining the context in which the author discovered the double optional pattern while working on a SwiftUI app.
- Main Body: Detailed explanation of how the pattern works, including Swift code snippets that demonstrate the use of double optionals to manage sheet presentation and mode (create/edit).
- Conclusion: The article concludes with a reflection on the "freaky" nature of double optionals and their utility in SwiftUI for managing complex state scenarios.
Additional Resourcesβ
- SwiftUI Documentation: π SwiftUI Framework Documentation
- Optional Binding in Swift: π Understanding Optional Binding
π΅ Enhancements in Pulse 3.2: Advanced Search, List Management, and Moreβ
This blog post dives into the exciting new features introduced in Pulse version 3.2, focusing on the revamped search functionality, optimized list performance, and new tools for sorting and grouping logs. These enhancements, made possible by SwiftUI's .searchable
modifier and other innovations, significantly improve the usability and efficiency of Pulse for iOS developers.
Details
URL: π https://kean.blog/post/pulse-search
Published: January 24, 2023
Authors: Alex Grebenyuk
Tags:
iOS
, SwiftUI
, Pulse
, Search
, UI Components
Key Pointsβ
- SwiftUI
.searchable
modifier: A powerful tool introduced in iOS 15, now enhanced with token support in iOS 16, streamlining the search experience in Pulse. - Optimized List Handling: Overcomes performance issues in List by limiting the displayed items and using dynamic loading as users scroll, ensuring smooth performance.
- Advanced Grouping and Sorting: New toolbar features allow for detailed grouping and sorting of logs, helping developers quickly find the information they need.
- Pinning for Quick Access: Reintroduced pins feature, allowing important logs to be pinned and easily accessed.
Summary of Contentsβ
- Introduction to Pulse 3.2: Overview of the major updates, emphasizing the role of search and list management in improving user experience.
- Search Enhancements: Detailed look at how the
.searchable
modifier and tokenization enhance search capabilities. - Handling Large Lists: Explanation of the strategy used to optimize list performance, including the decision to revert to UITableView for heavy lifting.
- Grouping and Sorting: Insight into the new grouping and sorting functionalities, especially the βGroup by Sessionβ feature.
- Reintroduction of Pins: Description of the pins feature, highlighting its utility for developers.
Additional Resourcesβ
- π Appleβs βAdding Search to Your Appβ: Official documentation on the
.searchable
modifier. - π Pulse GitHub Repository: Access to the source code and further details about Pulse.
- π Regex Combinators: Background on the parser combinators used in Pulseβs search feature.
π΅ Understanding SwiftUI's PreferenceKeysβ
The article explains how the PreferenceKey
protocol in SwiftUI allows child views to send values up the view hierarchy to parent views, which is the opposite of how Environment variables work, where data flows down the hierarchy. This technique is essential for cases where data needs to be passed upwards without relying on state variables or bindings.
Details
URL: π https://swiftlogic.io/posts/understanding-swiftui-preferencekeys/
Published: Jul 21, 2024
Authors: Osaretin Uyigue
Tags:
swift
, swiftui
, ios development
, preference keys
, data flow
, data binding
Key Pointsβ
- PreferenceKey Protocol: Enables the upward flow of data in SwiftUI, contrary to the typical downward data flow.
- Custom
PreferenceKeys
: Demonstrated with examples, allowing child views to communicate their heights to a parent view. - Real-World Use: Includes a practical example of a custom navigation title that leverages
PreferenceKeys
.
Summary of Contentsβ
- How it Works: An overview of how data typically flows in SwiftUI and how
PreferenceKeys
invert this flow. - How
PreferenceKeys
Work: A breakdown of thePreferenceKey
protocol and how it allows child views to send values upwards. - Creating a Custom
PreferenceKey
: Step-by-step guide to creating a customPreferenceKey
to pass data up the view hierarchy. - Using
PreferenceKeys
in Views: An example implementation showing how to usePreferenceKeys
in child and parent views. - Real-World Use Case: A demonstration of using
PreferenceKeys
to set a custom navigation title in a SwiftUI view.
Additional Resourcesβ
- π Leveraging ToolbarContentBuilder to Refactor Your SwiftUI Toolbar Code: Discusses the use of
ToolbarContentBuilder
, another powerful tool in SwiftUI. - π How to Inject Dependencies into SwiftUI @StateObject: A tutorial on dependency injection with
@StateObject
in SwiftUI.
π΅ Customizing the Appearance of Symbol Images in SwiftUIβ
This blog post by Natalia Panferova provides a comprehensive guide on customizing SF Symbols in SwiftUI. The article covers essential techniques such as adjusting symbol size, color customization, rendering modes, variable values, and design variants to enhance the visual consistency and user experience in iOS apps. By following these methods, developers can create more intuitive and visually appealing interfaces.
Details
URL: π https://nilcoalescing.com/blog/CustomizingTheAppearanceOfSymbolImagesInSwiftUI/
Published: July 22, 2024
Authors: Natalia Panferova
Tags:
SwiftUI
, iOS
, SF Symbols
, UI Design
, Swift
Key Pointsβ
- Size Adjustment: Learn how to scale SF Symbols in SwiftUI by using the
**font()**
and**imageScale()**
modifiers. - Color Customization: Explore how to apply colors and gradients to symbols using the
**foregroundStyle()**
modifier. - Rendering Modes: Understand different rendering modes like Monochrome, Hierarchical, Palette, and Multicolor, and how they impact symbol appearance.
- Variable Values: Discover how to dynamically change a symbolβs appearance based on state using variable values.
- Design Variants: Utilize design variants like fill and slash to communicate different states or actions in your UI.
Summary of Contentsβ
- Size: Techniques for scaling and adjusting the weight of symbols in SwiftUI to ensure visual consistency.
- Color: Customizing symbol colors, including the use of gradients and other
**ShapeStyle**
options. - Rendering Modes: Detailed explanation of different rendering modes and their practical applications in UI design.
- Variable Value: How to use variable values to represent dynamic states in your app, such as volume or battery level.
- Design Variants: Applying design variants like fill, slash, and enclosures to SF Symbols for enhanced UI clarity.
Additional Resourcesβ
- Enhanced replace transition for SF Symbols in iOS 18: π Learn more about advanced transitions for SF Symbols
- Reading and setting color scheme in SwiftUI: π Guide on handling color schemes in SwiftUI
π΅ How to Customise the SwiftUI List Style and Background Colorβ
This article dives deep into customizing the appearance of SwiftUI List views. The tutorial covers how to adjust list background colors, modify separators, and use custom cells. With step-by-step examples, youβll learn how to make your List views stand out with unique styles beyond the default options provided by SwiftUI. Whether you're new to SwiftUI or looking to refine your UI design skills, this guide is packed with practical tips and code snippets.
Details
Published: 2023-02-01
Authors: Karin Prater
Tags:
SwiftUI
, iOS Development
, UI Design
, List Customization
Key Pointsβ
- Learn how to customize SwiftUI List styles, including background colors, separators, and insets.
- Practical code snippets for implementing unique list styles.
- Detailed examples of customizing list row height and modifying section headers and footers.
Summary of Contentsβ
- Example Data Structure: Introduction to a custom
Food
struct used throughout the examples. - Using a Custom Cell: How to create and implement custom cells in your List view.
- List Separators: Techniques for hiding and coloring row and section separators.
- List Row Size and Insets: Adjusting row height and modifying insets for a more polished look.
- Changing the SwiftUI List Background Color: Methods for changing both list and cell background colors.
- Extravagant Example: A showcase of the full range of customizations possible with SwiftUI Lists.
Additional Resourcesβ
- π SwiftUI List View: A Deep Dive into one of the most important components of SwiftUI.: A comprehensive guide to understanding SwiftUI List views.
- π SwiftUI Layout Cookbook: A free mini-book to master SwiftUI layouts.
π΅ Programmatically Trigger SwiftUI Actionsβ
This article discusses five different methods to programmatically trigger actions in SwiftUI, focusing on the onChange operator introduced in SwiftUI 2.0. It explores options ranging from basic boolean state management to advanced techniques using Combine and @Published properties.
Details
URL: π https://betterprogramming.pub/programmatically-trigger-swiftui-actions-be2dcb8acf0d
Published: 2020-09-14
Authors: Mark Lucking
Tags:
SwiftUI
, iOS Development
, State Management
, Swift
Key Pointsβ
- SwiftUI State Management: The article delves into various techniques for managing state and triggering UI changes in SwiftUI.
- onChange Operator: It highlights the new
onChange
operator in SwiftUI 2.0 and its applications. - Advanced State Control: Options 4 and 5 demonstrate more advanced state management strategies using
@Published
andCombine
.
Summary of Contentsβ
- Introduction: Overview of the need for triggering actions in SwiftUI, especially with the advent of SwiftUI 2.0.
- Option 1: Simple boolean state control for toggling UI elements based on a timer.
- Option 2: Enhanced state control using
onAppear
andonDisappear
with the id modifier for more responsive UI updates. - Option 3: Introduction of
onChange
to directly observe and react to state changes within a view. - Option 4: Using
@Published
andObservableObject
to manage state across multiple views without tightly coupling them. - Option 5: Utilizing Combineβs
PassthroughSubject
for even looser coupling and greater control over state-driven actions.
Additional Resourcesβ
- SwiftUI Documentation: π SwiftUI 2.0 Overview
- Combine Framework: π Introduction to Combine
π’ ScrollPosition for ScrollView in iOS 17 and SwiftUI 5β
This article discusses the new scrollPosition
modifier in SwiftUI 5, introduced with iOS 17, which allows developers to control the initial scroll position within a ScrollView
. The post includes code examples demonstrating how to implement this feature in various scenarios, such as creating a chat interface that starts at the bottom of the conversation.
Details
URL: π Link to the original blog post
Published: 2023-08-02
Authors: DevTechie
Tags:
SwiftUI
, iOS Development
, iOS 17
, ScrollView
, Swift
Key Pointsβ
- The
scrollPosition
modifier in SwiftUI 5 enables developers to set the initial scroll position in aScrollView
. - It can be used to replicate UI patterns like starting a conversation view from the bottom, similar to Apple's Messages app.
- The modifier supports various anchor points such as
.top
,.center
, and.bottom
, and it can be applied to both vertical and horizontal scrolls.
Summary of Contentsβ
- Introduction to scrollPosition Modifier: This section introduces the
scrollPosition
modifier and its significance in controlling the scroll view's initial position. - Chat Interface Example: Detailed example of creating a chat interface where the scroll starts at the bottom, mimicking the behavior of messaging apps.
- Application in Horizontal Scroll: Discusses how to apply
scrollPosition
to horizontal scrolls, including examples with images. - Advanced Use Cases: Explores other use cases, such as centering content in both horizontal and vertical scroll views.
Additional Resourcesβ
- SwiftUI Documentation: