mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
4d6e63e880
* Adds uncluttering dumped YAML manifest from `nil` entries. * Uses required type of a dictionary * Update CHANGELOG.md Co-authored-by: Maciej Piotrowski <maciej.piotrowski@allegro.pl>
34 lines
1.2 KiB
Swift
34 lines
1.2 KiB
Swift
extension Dictionary where Key == String, Value == Any? {
|
|
func removingEmptyArraysDictionariesAndNils() -> [String: Any] {
|
|
var new: [String: Any] = [:]
|
|
filter(outNil).forEach { pair in
|
|
let value: Any
|
|
if let array = pair.value as? [[String: Any?]] {
|
|
value = array.removingEmptyArraysDictionariesAndNils()
|
|
} else if let dictionary = pair.value as? [String: Any?] {
|
|
value = dictionary.removingEmptyArraysDictionariesAndNils()
|
|
} else {
|
|
value = pair.value! // nil is filtered out :)
|
|
}
|
|
new[pair.key] = value
|
|
}
|
|
return new
|
|
.filter(outEmptyArrays)
|
|
.filter(outEmptyDictionaries)
|
|
}
|
|
|
|
func outEmptyArrays(_ pair: (key: String, value: Any)) -> Bool {
|
|
guard let array = pair.value as? [Any] else { return true }
|
|
return !array.isEmpty
|
|
}
|
|
|
|
func outEmptyDictionaries(_ pair: (key: String, value: Any)) -> Bool {
|
|
guard let dictionary = pair.value as? [String: Any] else { return true }
|
|
return !dictionary.isEmpty
|
|
}
|
|
|
|
func outNil(_ pair: (key: String, value: Any?)) -> Bool {
|
|
return pair.value != nil
|
|
}
|
|
}
|