diff --git a/Linphone/Utils/MagicSearchSingleton.swift b/Linphone/Utils/MagicSearchSingleton.swift index 3ec990ea3..281b2e297 100644 --- a/Linphone/Utils/MagicSearchSingleton.swift +++ b/Linphone/Utils/MagicSearchSingleton.swift @@ -94,11 +94,13 @@ final class MagicSearchSingleton: ObservableObject { } } - let sortedLastSearch = lastSearchFriend.sorted(by: { - $0.friend!.name!.lowercased().folding(options: .diacriticInsensitive, locale: .current) - < - $1.friend!.name!.lowercased().folding(options: .diacriticInsensitive, locale: .current) - }) + let sortedLastSearch = lastSearchFriend.sorted { + let name1 = $0.friend?.name?.lowercased() + .folding(options: .diacriticInsensitive, locale: .current) ?? "" + let name2 = $1.friend?.name?.lowercased() + .folding(options: .diacriticInsensitive, locale: .current) ?? "" + return name1 < name2 + } var addedAvatarListModel: [ContactAvatarModel] = [] sortedLastSearch.forEach { searchResult in