File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -39,11 +39,15 @@ public struct CustomListRepository: CustomListRepositoryProtocol {
39
39
public func save( list: CustomList ) throws {
40
40
var lists = fetchAll ( )
41
41
42
- if let index = lists. firstIndex ( where: { $0. id == list. id } ) {
42
+ let persistedListWithSameName = lists. first {
43
+ $0. name. localizedCaseInsensitiveCompare ( list. name) == . orderedSame
44
+ }
45
+
46
+ if let persistedListWithSameName, persistedListWithSameName. id != list. id {
47
+ throw CustomRelayListError . duplicateName
48
+ } else if let index = lists. firstIndex ( where: { $0. id == list. id } ) {
43
49
lists [ index] = list
44
50
try write ( lists)
45
- } else if lists. contains ( where: { $0. name == list. name } ) {
46
- throw CustomRelayListError . duplicateName
47
51
} else {
48
52
lists. append ( list)
49
53
try write ( lists)
You can’t perform that action at this time.
0 commit comments