Swift

- Files
.swift- Formats as
- swift-format
- Lints
- Every rule that reads its code
- In
ur.toml [format.swift]
Formatted
Cart.swift, as written// What a cart costs.
struct Item {
let name: String
let price: Int
let quantity: Int
}
func subtotal(_ items: [Item]) -> Int {
var sum = 0
for item in items where item.quantity > 0 {
sum += item.price * item.quantity
}
return sum
}
let codes = [
"SPRING",
"WELCOME"
]
let range = 0 ..< codes.count
ur format --style swift-format Cart.swift// What a cart costs.
struct Item {
let name: String
let price: Int
let quantity: Int
}
func subtotal(_ items: [Item]) -> Int {
var sum = 0
for item in items where item.quantity > 0 {
sum += item.price * item.quantity
}
return sum
}
let codes = [
"SPRING",
"WELCOME",
]
let range = 0..<codes.count
Versions
Ur reads Swift as the profiles below name it. Name the versions a project targets in target; without it, Ur reads swift-6.
| Profile | Dialect |
|---|---|
swift-5 | Swiftc |
swift-6 | Swiftc |