# Swift style guide

**URL:** <https://forums.swift.org/t/swift-style-guide/60177>\
**Category:** Using Swift\
**Created:** [September 8, 2022, 7:07am UTC](https://forums.swift.org/t/swift-style-guide/60177 "2022-09-08T07:07:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [September 8, 2022, 10:05am UTC](https://forums.swift.org/t/swift-style-guide/60177/5 "2022-09-08T10:05:50Z")

</div>

I know you're asking for official guidelines, but for curiosity's sake I'll describe how I do it.

In your example, I would write:

```swift
/// I put three slashes above every "unit"
/// where a "unit" is non-rigorously defined
/// as simply whatever looks to me like a unit -
/// this serves a visual aid for parsing the code at a glance
/// and once in a while when it seems appropriate I put a comment
class Car {

    ///
    var name: String
    var price: Int
    
    ///
    init
        (name: String,
         price: Int) {

        ///
        self.name = name
        self.price = price
    }

    ///
    func update
        (name: String,
         price: Int) {

        ///
        self.name = name
        self.price = price
    }

    ///
    func someLongFunctionNameWithInputsAndGenericParamsAndReturnValue
        <Generic: Parameters,
         GetTheirOwnLine: And>
        (theInputs: Array<Generic>,
         areEasilyReadable: Bool,
         becauseTheirHorizontalLocation: CGFloat,
         isNotDependentOnTheLengthOfTheFunctionName: Bool)
    async throws -> (effectsAndReturnValue: String, areOnTheirOwnLine: String)
        where Generic.WhereClause: GetsItsOwnLineToo {

        ///
        ("Similar approach for formatting", "within the function body")
    }

    ///
    func shortFunctionSignatures () -> CanBeJustOneLine {
        ...
    }
}

```

One result is that almost all of my code could be comfortably viewed on a vertical iPhone.

---

_[View the full topic](https://forums.swift.org/t/swift-style-guide/60177)._
