forked from yonaskolb/XcodeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildSettingsExtractor.swift
More file actions
37 lines (34 loc) · 1.41 KB
/
BuildSettingsExtractor.swift
File metadata and controls
37 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
import JSONUtilities
/// A helper for extracting and validating the `Settings` object from a JSON dictionary.
struct BuildSettingsParser {
let jsonDictionary: JSONDictionary
/// Attempts to extract and parse the `Settings` from the dictionary.
///
/// - Returns: A valid `Settings` object
func parse() throws -> Settings {
do {
return try jsonDictionary.json(atKeyPath: "settings")
} catch let specParsingError as SpecParsingError {
// Re-throw `SpecParsingError` to prevent the misuse of settings.configs.
throw specParsingError
} catch {
// Ignore all errors except `SpecParsingError`
return .empty
}
}
/// Attempts to extract and parse setting groups from the dictionary with fallback defaults.
///
/// - Returns: Parsed setting groups or default groups if parsing fails
func parseSettingGroups() throws -> [String: Settings] {
do {
return try jsonDictionary.json(atKeyPath: "settingGroups", invalidItemBehaviour: .fail)
} catch let specParsingError as SpecParsingError {
// Re-throw `SpecParsingError` to prevent the misuse of settingGroups.
throw specParsingError
} catch {
// Ignore all errors except `SpecParsingError`
return jsonDictionary.json(atKeyPath: "settingPresets") ?? [:]
}
}
}