From a2684a96a45fad15bcd1cd962ad327fcc2d7211f Mon Sep 17 00:00:00 2001 From: Ell Neal Date: Sun, 13 Jan 2019 18:16:17 +0000 Subject: [PATCH] Replace global merge function with extension on Dictionary --- Sources/ProjectSpec/Settings.swift | 18 ------------------ Sources/ProjectSpec/Target.swift | 4 ++-- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/Sources/ProjectSpec/Settings.swift b/Sources/ProjectSpec/Settings.swift index 26d061bf..95254dd6 100644 --- a/Sources/ProjectSpec/Settings.swift +++ b/Sources/ProjectSpec/Settings.swift @@ -101,24 +101,6 @@ extension Dictionary where Key == String, Value: Any { } } -func merge(dictionary: JSONDictionary, onto base: JSONDictionary) -> JSONDictionary { - var merged = base - - for (key, value) in dictionary { - if key.hasSuffix(":REPLACE") { - let newKey = key.replacingOccurrences(of: ":REPLACE", with: "") - merged[newKey] = value - } else if let dictionary = value as? JSONDictionary, let base = merged[key] as? JSONDictionary { - merged[key] = merge(dictionary: dictionary, onto: base) - } else if let array = value as? [Any], let base = merged[key] as? [Any] { - merged[key] = base + array - } else { - merged[key] = value - } - } - return merged -} - public func += (lhs: inout BuildSettings, rhs: BuildSettings?) { guard let rhs = rhs else { return } lhs.merge(rhs) diff --git a/Sources/ProjectSpec/Target.swift b/Sources/ProjectSpec/Target.swift index 10218fad..b7727e66 100644 --- a/Sources/ProjectSpec/Target.swift +++ b/Sources/ProjectSpec/Target.swift @@ -125,10 +125,10 @@ extension Target { var mergedDictionary: JSONDictionary = [:] for template in templates { if let templateDictionary = targetTemplatesDictionary[template] { - mergedDictionary = merge(dictionary: templateDictionary, onto: mergedDictionary) + mergedDictionary = templateDictionary.merged(onto: mergedDictionary) } } - target = merge(dictionary: target, onto: mergedDictionary) + target = target.merged(onto: mergedDictionary) } targetsDictionary[targetName] = target }