mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Merge pull request #50 from antoniocasero/master
Filter out NSNull elements from the json dictionary.
This commit is contained in:
@@ -16,7 +16,8 @@ public struct SpecLoader {
|
||||
|
||||
public static func loadSpec(path: Path) throws -> ProjectSpec {
|
||||
let dictionary = try loadDictionary(path: path)
|
||||
return try ProjectSpec(jsonDictionary: dictionary)
|
||||
let filteredDictionary = SpecLoader.filterNull(dictionary) as! [String:Any]
|
||||
return try ProjectSpec(jsonDictionary: filteredDictionary)
|
||||
}
|
||||
|
||||
private static func loadDictionary(path: Path) throws -> JSONDictionary {
|
||||
@@ -52,4 +53,23 @@ public struct SpecLoader {
|
||||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
private static func filterNull(_ object:Any) -> Any {
|
||||
var returnedValue : Any = object
|
||||
if let dict = object as? [String:Any] {
|
||||
var mutabledic : [String: Any] = [:]
|
||||
for (key, value) in dict {
|
||||
mutabledic[key] = SpecLoader.filterNull(value)
|
||||
}
|
||||
returnedValue = mutabledic
|
||||
}
|
||||
else if let array = object as? [Any] {
|
||||
var mutableArray: [Any] = array
|
||||
for (index, value) in array.enumerated() {
|
||||
mutableArray[index] = SpecLoader.filterNull(value)
|
||||
}
|
||||
returnedValue = mutableArray
|
||||
}
|
||||
return (object is NSNull) ? "" : returnedValue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user