Replace global merge function with extension on Dictionary

This commit is contained in:
Ell Neal 2019-01-13 18:16:17 +00:00
parent 8928088dfe
commit a2684a96a4
No known key found for this signature in database
GPG Key ID: 0AAD6C98BA484C61
2 changed files with 2 additions and 20 deletions

View File

@ -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)

View File

@ -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
}