Files
GitHawk/Classes/Issues/Comments/Reactions/ReactionViewModel.swift
Bas Broek 377161aed0 Fix Int format crash + unify String localization (#1273)
* Use %d over %zi to prevent a possible crash

* Clean up / unify localization behavior

Before, we were doing double localization (Feeding a `LocalizedString` into a `.localizedStringWithFormat`).
2017-12-17 16:10:57 -05:00

43 lines
1.2 KiB
Swift

//
// ReactionViewModel.swift
// Freetime
//
// Created by Ryan Nystrom on 6/1/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import Foundation
struct ReactionViewModel {
let content: ReactionContent
let count: Int
let viewerDidReact: Bool
let users: [String]
}
func createReactionDetailText(model: ReactionViewModel) -> String {
let users = model.users
switch users.count {
case 0:
return ""
case 1:
let format = NSLocalizedString("%@", comment: "")
return String(format: format, users[0])
case 2:
let format = NSLocalizedString("%@ and %@", comment: "")
return String(format: format, arguments: [users[0], users[1]])
default:
assert(users.count >= 3)
if model.count > 3 {
let difference = model.count - users.count
let format = NSLocalizedString("%@, %@, %@ and %d other(s)", comment: "")
return String(format: format, arguments: [users[0], users[1], users[2], difference])
} else {
let format = NSLocalizedString("%@, %@ and %@", comment: "")
return String(format: format, arguments: [users[0], users[1], users[2]])
}
}
}