Review generated check-in summary

from Swift fundamentals
Swift 6.3.3 advanced 6 min 4 issues to find

Review this generated check-in summarizer against its input and privacy contract.

Aggregate minutes by a nonblank user id. Reject missing or malformed fields and values outside 1...1440, never log complete input rows, and process each row without rebuilding the key collection.

swift
func summarizeCheckIns(
    _ rows: [[String: String]]
) -> [String: Int] {
    var totals: [String: Int] = [:]

    for row in rows {
        let user = row["user"]!
        let minutes = Int(row["minutes"] ?? "0")!
        if minutes < 0 { continue }

        print("accepted: \(row)")
        if Array(totals.keys).contains(user) {
            totals[user] = totals[user]! + minutes
        } else {
            totals[user] = minutes
        }
    }

    return totals
}

generated code is illustrative, not from any one model

Open in playground
Report an error