Back to walidsassi.com

Understanding `@ViewBuilder` in SwiftUI: Build Custom Views with Declarative Syntax

SwiftUI’s @ViewBuilder is a powerful attribute that enables us to create custom view components with a declarative and flexible syntax, just like native SwiftUI containers (VStack, HStack, etc.). In this article, we’ll explore: What is @ViewBuilder and why it matters How to create a custom view that accepts a @ViewBuilder closure What happens under the hood when SwiftUI processes a @ViewBuilder closure Practical use cases and benefits What is @ViewBuilder? @ViewBuilder is a special attribute that lets you write multiple views inside a closure, and SwiftUI will automatically combine them into a single view result. It acts like a function builder specialized for views. ...

June 28, 2025 · 2 min · Walid Sassi

Understanding Dependency Cycles: How SparkDI Uses DFS for Detection

Imagine you’re building a house of cards. Each card depends on others for support, creating a delicate but stable structure. Now imagine two cards needed to support each other simultaneously, it would be physically impossible to build. This is exactly the problem we face with dependencies in software development. 🔁 A Real-World Example In this scenario: AuthenticationService needs UserService to verify user permissions UserService needs ProfileService to get user details ProfileService needs AuthenticationService to access secure data This creates an impossible situation: none of these services can be initialized because each depends on another that isn’t yet created. It’s like trying to solve the classic chicken-and-egg problem. ...

February 24, 2025 · 2 min · Walid Sassi