Swift 代码格式化工具

专业级的 Swift 代码格式化、压缩与美化

struct Item {
    let name: String
    let price: Double
    let quantity: Int
}

func calculateTotal(items: [Item]) -> Double {
    var total = 0.0
    for item in items {
        total += item.price * Double(item.quantity)
    }

    if total > 1000 {
        total *= 0.9 // 10% discount
    }

    return total
}

let items = [
    Item(name: "MacBook Pro", price: 1999.0, quantity: 1),
    Item(name: "iPhone", price: 999.0, quantity: 2),
    Item(name: "AirPods", price: 199.0, quantity: 1)
]

print("Total amount: \(calculateTotal(items: items))")