From 46e3e9d14e4143729bb213af4e1c495cbd79fc18 Mon Sep 17 00:00:00 2001 From: fortmarek Date: Thu, 20 Feb 2025 17:58:33 +0100 Subject: [PATCH] fix: remove duplicates when combining settings in order --- Package.resolved | 6 ++--- .../SettingsDictionary+Extras.swift | 26 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Package.resolved b/Package.resolved index b4ca42d7..64056eaf 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "11c91097a7d3815aa19aa8bdc65446d1e51f2b556e7afb8fdff27ce1384ed4b6", + "originHash" : "e00b9b258083e5d180326ee4f3fedbcfea7db4ae854a2bf6745abd5db9a73971", "pins" : [ { "identity" : "aexml", @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/Command.git", "state" : { - "revision" : "07846291097a593de29846c0083b758471071cdf", - "version" : "0.12.2" + "revision" : "079a7803b581d3022469b3a331bccd51d48d2fc0", + "version" : "0.13.0" } }, { diff --git a/Sources/XcodeGraph/Extensions/SettingsDictionary+Extras.swift b/Sources/XcodeGraph/Extensions/SettingsDictionary+Extras.swift index 35a588d8..f24ff797 100644 --- a/Sources/XcodeGraph/Extensions/SettingsDictionary+Extras.swift +++ b/Sources/XcodeGraph/Extensions/SettingsDictionary+Extras.swift @@ -1,4 +1,5 @@ import Foundation +import XcodeProj extension SettingsDictionary { /// Overlays a SettingsDictionary by adding a `[sdk=*]` qualifier @@ -32,19 +33,28 @@ extension SettingsDictionary { switch oldValue { case let .array(values): return .array( - Array( - Set(values + newValues) - ) + (values + newValues) + .uniqued() ) case let .string(value): return .array( - Array( - Set( - value.split(separator: " ").map(String.init) + newValues - ) - ) + (value.split(separator: " ").map(String.init) + newValues) + .uniqued() ) } }) } } + +extension Array where Element: Hashable { + /// Return the array with all duplicates removed in order. + /// + /// i.e. `[ 1, 2, 3, 1, 2 ].uniqued() == [ 1, 2, 3 ]` + /// + /// - note: Taken from stackoverflow.com/a/46354989/3141234, as + /// per @Alexander's comment. + fileprivate func uniqued() -> [Element] { + var seen = Set() + return filter { seen.insert($0).inserted } + } +}