@@ -15,23 +15,17 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl
1515 self . groups = groups
1616 }
1717
18- public init ( dictionary: [ String : Any ] ) {
19- buildSettings = dictionary
20- configSettings = [ : ]
21- groups = [ ]
22- }
23-
24- public static let empty : Settings = Settings ( dictionary: [ : ] )
18+ public static let empty : Settings = Settings ( buildSettings: [ : ] )
2519
2620 public init ( jsonDictionary: JSONDictionary ) throws {
2721 if jsonDictionary [ " configs " ] != nil || jsonDictionary [ " groups " ] != nil || jsonDictionary [ " base " ] != nil {
2822 groups = jsonDictionary. json ( atKeyPath: " groups " ) ?? jsonDictionary. json ( atKeyPath: " presets " ) ?? [ ]
2923 let buildSettingsDictionary : JSONDictionary = jsonDictionary. json ( atKeyPath: " base " ) ?? [ : ]
30- buildSettings = buildSettingsDictionary
24+ buildSettings = buildSettingsDictionary. mapValues { BuildSetting ( any : $0 ) }
3125
3226 self . configSettings = try Self . extractValidConfigs ( from: jsonDictionary)
3327 } else {
34- buildSettings = jsonDictionary
28+ buildSettings = jsonDictionary. mapValues { BuildSetting ( any : $0 ) }
3529 configSettings = [ : ]
3630 groups = [ ]
3731 }
@@ -58,7 +52,7 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl
5852 }
5953
6054 public static func == ( lhs: Settings , rhs: Settings ) -> Bool {
61- NSDictionary ( dictionary : lhs. buildSettings) . isEqual ( to : rhs. buildSettings) &&
55+ lhs. buildSettings == rhs. buildSettings &&
6256 lhs. configSettings == rhs. configSettings &&
6357 lhs. groups == rhs. groups
6458 }
@@ -96,14 +90,14 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl
9690
9791extension Settings : ExpressibleByDictionaryLiteral {
9892
99- public init ( dictionaryLiteral elements: ( String , Any ) ... ) {
100- var dictionary : [ String : Any ] = [ : ]
101- elements. forEach { dictionary [ $0. 0 ] = $0. 1 }
102- self . init ( dictionary : dictionary )
93+ public init ( dictionaryLiteral elements: ( String , BuildSetting ) ... ) {
94+ var buildSettings : BuildSettings = [ : ]
95+ elements. forEach { buildSettings [ $0. 0 ] = $0. 1 }
96+ self . init ( buildSettings : buildSettings )
10397 }
10498}
10599
106- extension Dictionary where Key == String , Value : Any {
100+ extension Dictionary where Key == String {
107101
108102 public func merged( _ dictionary: [ Key : Value ] ) -> [ Key : Value ] {
109103 var mergedDictionary = self
@@ -116,26 +110,56 @@ extension Dictionary where Key == String, Value: Any {
116110 self [ key] = value
117111 }
118112 }
119-
120- public func equals( _ dictionary: BuildSettings ) -> Bool {
121- NSDictionary ( dictionary: self ) . isEqual ( to: dictionary)
122- }
123113}
124114
125115public func += ( lhs: inout BuildSettings , rhs: BuildSettings ? ) {
126116 guard let rhs = rhs else { return }
127117 lhs. merge ( rhs)
128118}
129119
120+ extension BuildSetting {
121+
122+ public init ( any value: Any ) {
123+ if let array = value as? [ String ] {
124+ self = . array( array)
125+ } else if let bool = value as? Bool {
126+ self = . init( booleanLiteral: bool)
127+ } else {
128+ self = . string( " \( value) " )
129+ }
130+ }
131+
132+ public func toAny( ) -> Any {
133+ switch self {
134+ case let . string( value) : return value
135+ case let . array( value) : return value
136+ }
137+ }
138+ }
139+
140+ extension ProjectAttribute {
141+
142+ public init ( any value: Any ) {
143+ if let array = value as? [ String ] {
144+ self = . array( array)
145+ } else if let object = value as? PBXObject {
146+ self = . targetReference( object)
147+ } else {
148+ self = . string( " \( value) " )
149+ }
150+ }
151+ }
152+
130153extension Settings : JSONEncodable {
131154 public func toJSONValue( ) -> Any {
155+ let anySettings = buildSettings. mapValues { $0. toAny ( ) }
132156 if groups. count > 0 || configSettings. count > 0 {
133157 return [
134- " base " : buildSettings ,
158+ " base " : anySettings ,
135159 " groups " : groups,
136160 " configs " : configSettings. mapValues { $0. toJSONValue ( ) } ,
137161 ] as [ String : Any ]
138162 }
139- return buildSettings
163+ return anySettings
140164 }
141165}
0 commit comments