# I'm confused how to consistently format Swift code

**URL:** <https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780>\
**Category:** Swift Format\
**Tags:** swift-format, format, formatter, formatting\
**Created:** [August 23, 2025, 3:41am UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780 "2025-08-23T03:41:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukaszciastko](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@lukaszciastko](https://forums.swift.org/u/lukaszciastko)\
**Post date:** [August 23, 2025, 3:41am UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/1 "2025-08-23T03:41:59Z")

</div>

Hi,

I’ve been trying to find a consistent way to format my code, but I’m confused how it all works…

Is there a way to format code from command line in the same way Xcode (Format file with ‘swift-format’) or VS Code (Shift+Option+F) format the code? For example, here is some code formatted by Xcode/VS Code:

```swift
struct Item {
    let id: String
}

```

Now, if I try to run the `swift format . --recursive --in-place` command, the number of spaces is different:

```swift
struct Item {
  let id: String
}

```

This is annoying, because when I try to reformat all my code, the indentation changes everywhere. I can see that Xcode mentions formatting code with ‘swift-format’ as oppose to ‘swift format’, but I don’t really know what the difference is - and relying on Google or even AI to explain this is very hard, because the name is pretty much the same.

---

<div class="post-metadata">

**Author:** ![andreas66](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/andreas66/32/19882_2.png) [@andreas66](https://forums.swift.org/u/andreas66)\
**Post date:** [August 23, 2025, 7:00am UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/2 "2025-08-23T07:00:57Z")

</div>

Have you tried using a [configuration file](https://github.com/swiftlang/swift-format/blob/main/Documentation/Configuration.md)

---

<div class="post-metadata">

**Author:** ![bbrk24](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bbrk24/32/27370_2.png) [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Post date:** [August 24, 2025, 4:12am UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/3 "2025-08-24T04:12:12Z")

</div>

> [@lukaszciastko](#):
>
> I can see that Xcode mentions formatting code with ‘swift-format’ as oppose to ‘swift format’, but I don’t really know what the difference is

`swift-format` and `swift format` are just two different ways of spelling the same command. There is another thing that is actually different though, and that's [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) in PascalCase.

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [August 24, 2025, 8:38am UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/4 "2025-08-24T08:38:41Z")

</div>

> [@bbrk24](#):
>
> that's [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) in PascalCase

I love the icon/logo there! I didn't know we had an ASCII Swift emoji **`=}`**

What about `PascalCase` - I hope this is configurable.

---

<div class="post-metadata">

**Author:** ![bbrk24](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bbrk24/32/27370_2.png) [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Post date:** [August 24, 2025, 2:42pm UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/5 "2025-08-24T14:42:11Z")

</div>

Yes, they have a "Configuration" section in the README.

---

<div class="post-metadata">

**Author:** ![ZevEisenberg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/zeveisenberg/32/11574_2.png) [@ZevEisenberg](https://forums.swift.org/u/ZevEisenberg)\
**Post date:** [August 25, 2025, 12:01pm UTC](https://forums.swift.org/t/im-confused-how-to-consistently-format-swift-code/81780/6 "2025-08-25T12:01:47Z")

</div>

> [@dima\_kozhinov](#):
>
> What about `PascalCase` - I hope this is configurable.

I believe they meant that the _name_ of SwiftFormat, the non-Apple-official tool built by Nick Lockwood, is spelled in Pascal case, otherwise known as upper camel case.
