Swift & SwiftUI Beautifier

Swift Code Formatter & Beautifier

Standardize messy Swift code, align nested SwiftUI view closures, balance braces, and remove trailing whitespace before committing or sharing snippets.

Presets:
Unformatted Swift Code43 lines
Beautified Swift43 lines
import SwiftUI

struct UserProfileCard: View {
    @State private var isFollowing: Bool = false
    @State private var followerCount: Int = 1420
    var username: String

    var body: some View {
        VStack(alignment: .leading, spacing: 12){
            HStack(spacing: 14){
                Image(systemName: "person.crop.circle.fill")
                .resizable()
                .frame(width: 56, height: 56)
                .foregroundStyle(.tint)
                VStack(alignment:.leading, spacing: 4){
                    Text(username)
                    .font(.headline)
                    Text("\(followerCount) followers")
                    .font(.caption)
                    .foregroundStyle(.secondary)
                }
                Spacer()
                Button(action:{
                        withAnimation(.spring()){
                            isFollowing.toggle()
                            followerCount += isFollowing ? 1 : -1
                        }
                }){
                    Text(isFollowing ? "Following" : "Follow")
                    .font(.subheadline.weight(.semibold))
                    .padding(.horizontal, 16)
                    .padding(.vertical, 8)
                    .background(isFollowing ? Color.secondary.opacity(0.15) : Color.accentColor)
                    .foregroundStyle(isFollowing ? .primary : .white)
                    .clipShape(Capsule())
                }
            }
        }
        .padding(16)
        .background(.ultraThinMaterial)
        .clipShape(RoundedRectangle(cornerRadius: 16))
    }
}

Official Swift Style Guide Conventions

4-Space Standard

Apple’s official Swift style guideline favors 4-space indentation for code blocks, nested struct bodies, and closures, while SwiftUI view modifier chains are indented by 4 spaces.

Trailing Closure Spacing

Closures like Button(action: { ... }) should maintain balanced spacing before the opening brace and uniform indentation inside the action body.

Colon & Operator Padding

Type annotations require no space before the colon and one space after (var count: Int). Operators must maintain symmetrical padding (x + y).

Thorous icon

Build full iPhone apps without touching Xcode

Enjoying this free Swift Formatter? Thorous turns your natural language prompts into compiled native SwiftUI apps, with real-time iOS simulator streaming and visual on-screen editing.

Native Mac app · macOS 14 Sonoma or later · Apple silicon & Intel