Skip to content

Commit

Permalink
Merge pull request #354 from Infomaniak/fix-contact-color
Browse files Browse the repository at this point in the history
Prevent force unwrap
  • Loading branch information
Lnamw committed Oct 12, 2022
2 parents e2ba597 + 5f646dd commit dff0f74
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion MailCore/Models/MergedContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public class MergedContact {

private let contactFormatter = CNContactFormatter()

public lazy var color = UIColor(hex: remote!.color) ?? UserDefaults.shared.accentColor.primary.color
public lazy var color: UIColor = {
if let remoteColorHex = remote?.color,
let colorFromHex = UIColor(hex: remoteColorHex) {
return colorFromHex
} else {
return UserDefaults.shared.accentColor.primary.color
}
}()

public lazy var name: String = {
if let local = local, let localName = contactFormatter.string(from: local) {
Expand Down

0 comments on commit dff0f74

Please sign in to comment.