Filter out NSNull elements from the json dictionary.

This change allows us to override default BuildSettings.
For example:

If I want to keep the attribute SWIFT_OBJC_INTERFACE_HEADER_NAME empty,
(by default it contains some value). I just need to override this value
in the settings spec.

Before If I keep property empty, then in the generated settings the value
appear as <null>.

The method implemented recursively loop through the json dictionary
looking for NSNull objects and replace them by an empty string.

Filter out NSNull elements from the json dictionary.

This change allows us to override default BuildSettings.
For example:

If I want to keep the attribute SWIFT_OBJC_INTERFACE_HEADER_NAME empty,
(by default it contains some value). I just need to override this value
in the settings spec.

Before If I keep property empty, then in the generated settings the value
appear as <null>.

The method implemented recursively loop through the json dictionary
looking for NSNull objects and replace them by an empty string.
This commit is contained in:
Palmero, Antonio
2017-09-13 13:58:32 +02:00
parent 714daa8b7f
commit 62f72d39bc
+21 -1
View File
@@ -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
}
}