Handle user initials generation from first and last name

This commit is contained in:
Benoit Martins 2026-04-20 12:26:28 +02:00
parent 30de5c1666
commit f9246f1f25
2 changed files with 19 additions and 4 deletions

View file

@ -197,9 +197,24 @@ final class ContactsManager: ObservableObject {
}
func textToImage(firstName: String?, lastName: String?) -> UIImage {
let firstInitial = firstName?.first.map { String($0) } ?? ""
let lastInitial = lastName?.first.map { String($0) } ?? ""
let textToDisplay = (firstInitial + lastInitial).uppercased()
let firstParts = firstName?
.split(separator: " ")
.map(String.init) ?? []
let firstInitial = firstParts.first?.first.map(String.init) ?? ""
let secondInitial = firstParts.count > 1 ? firstParts[1].first.map(String.init) ?? "" : ""
let lastInitial = lastName?.first.map(String.init) ?? ""
let textToDisplay: String
if !firstInitial.isEmpty && !secondInitial.isEmpty {
textToDisplay = firstInitial + secondInitial
} else if !firstInitial.isEmpty {
textToDisplay = firstInitial + lastInitial
} else {
textToDisplay = lastInitial
}
let size = CGSize(width: 200, height: 200)
let renderer = UIGraphicsImageRenderer(size: size)

View file

@ -2,6 +2,6 @@ import Foundation
public enum AppGitInfo {
public static let branch = "release/6.2"
public static let commit = "4e93c8f4b"
public static let commit = "30de5c166"
public static let tag = "6.2.0-beta"
}