Member-only story
14 Must-Have SwiftUI Code Extensions
Optimizing your code for simplicity

Discover a curated collection of essential SwiftUI code extensions that will revolutionize your iOS development workflow. These powerful extensions serve as invaluable tools for streamlining common tasks, enhancing code readability, and boosting your productivity when building modern iOS applications.
From simplifying view modifications and handling complex animations to managing data transformations and UI component customizations, these 18 carefully selected extensions represent the fundamental building blocks that every SwiftUI developer should have in their toolbox to write cleaner, more maintainable, and efficient code.
1. Extension for Print in View
So, we often debug using “Print,” including myself. However, doing this in SwiftUI is more challenging compared to UIKit. Therefore, I found this solution to make it easier. Here, I will also provide an example of how to use it.
import SwiftUI
// MARK: Print in SwiftUI
extension View {
func Print(_ vars: Any...) -> some View {
for value in vars { print(value) }
return EmptyView()
}
}
How to use the code extension
struct ProjectSwiftUITests: View {
let maka: String = "maka"
var body: some View {
VStack(alignment: .leading) {
Text("Hello, World!")
Print(maka, "0")
// maka
// 0
}
}
}
#Preview {
ProjectSwiftUITests()
}

2. Extension View Corner Radius
Corner radius is an important and frequently used aspect of UI in SwiftUI. There are several ways to create it, and while the standard methods are not too lengthy, we often modify them for better results. Below is the code I created using an extension.
extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape(RoundedCorner(radius: radius, corners: corners))
}
}
struct RoundedCorner: Shape {
var…