diff --git a/ios/MullvadSettings/CustomListRepository.swift b/ios/MullvadSettings/CustomListRepository.swift index 4466b2f9aa7d..c6709782e2b2 100644 --- a/ios/MullvadSettings/CustomListRepository.swift +++ b/ios/MullvadSettings/CustomListRepository.swift @@ -39,11 +39,12 @@ public struct CustomListRepository: CustomListRepositoryProtocol { public func save(list: CustomList) throws { var lists = fetchAll() - if let index = lists.firstIndex(where: { $0.id == list.id }) { + if let listWithSameName = lists.first(where: { $0.name.caseInsensitiveCompare(list.name) == .orderedSame }), + listWithSameName.id != list.id { + throw CustomRelayListError.duplicateName + } else if let index = lists.firstIndex(where: { $0.id == list.id }) { lists[index] = list try write(lists) - } else if lists.contains(where: { $0.name == list.name }) { - throw CustomRelayListError.duplicateName } else { lists.append(list) try write(lists)