@@ -99,19 +99,16 @@ private func isKeyPresentInOptionalDictionary(keyToSearch: String, tupleKey: Str
9999Checking the key is present in all the plists
100100*/
101101private func isKeyAvailableInAllPlists( keyToSearch: String , tupleKey: String , tuplesForPlists: [ String : KeyValueTuples ] ) -> Bool {
102- let plistPaths = tuplesForPlists. keys
103- for plistPath in plistPaths {
102+ for plistPath in tuplesForPlists. keys {
104103
105- guard let tuples = tuplesForPlists [ plistPath] else {
106- return false
107- }
108-
109- guard let dictionary = tuples [ tupleKey] as? Dictionary < String , Any > else {
104+ guard
105+ let tuples = tuplesForPlists [ plistPath] ,
106+ let dictionary = tuples [ tupleKey] as? Dictionary < String , Any > else {
110107 return false
111108 }
112109
113110 if ( dictionary. keys. contains ( keyToSearch) == false ) {
114- return false
111+ return false
115112 }
116113 }
117114
@@ -122,19 +119,19 @@ private func isKeyAvailableInAllPlists(keyToSearch: String, tupleKey: String, tu
122119Generate Protocol for the Tuples and return the optional dictionary
123120*/
124121private func generateProtocol( tuplesForPlists: [ String : KeyValueTuples ] , allKeyValueTuples: [ String : KeyValueTuples ] ) -> [ String : [ String : String ] ] {
125- var optionalDictionary : [ String : [ String : String ] ] = [ : ]
122+ var optionalDictionary = [ String: [ String: String] ] ( )
126123 for (tupleKey, tuples) in allKeyValueTuples {
127124
128125 let name = tupleKey. uppercaseFirst ( )
129126 let protocolName = name. appending ( " Protocol " )
130127 print ( " protocol \( protocolName) { " )
131128 intend ( )
132129
133- var optionalKeysAndTypes : [ String : String ] = [ : ]
130+ var optionalKeysAndTypes = [ String: String] ( )
134131 for tuple in tuples. tuples {
135- let isOptional = ! ( isKeyAvailableInAllPlists ( keyToSearch: tuple. key, tupleKey: tupleKey, tuplesForPlists: tuplesForPlists) )
132+ let isKeyPresentInAllPlists = isKeyAvailableInAllPlists ( keyToSearch: tuple. key, tupleKey: tupleKey, tuplesForPlists: tuplesForPlists)
136133 var type = typeForValue ( tuple. value as Any )
137- if ( isOptional == true ) {
134+ if ( isKeyPresentInAllPlists == false ) {
138135 type = " \( type) ? "
139136 optionalKeysAndTypes [ tuple. key] = type
140137 }
@@ -273,7 +270,7 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
273270 print ( " \n \( tabs ( ) ) internal struct \( structName) \( conformingToProtocol) { " )
274271 intend ( )
275272
276- var availableKeys : [ String ] = [ ]
273+ var availableKeys = [ String ] ( )
277274 for tuple in tuples. tuples {
278275
279276 let tupleKey = tuple. key
@@ -312,11 +309,13 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
312309 let boolString = ( ( ( tupleValue as? Bool ) == true ) ? " true " : " false " )
313310 print ( " \( tabs ( ) ) internal var \( tupleKey. lowercaseFirst ( ) ) : \( type) ? = \( boolString) " )
314311 case " Array<Any> " where ( isOptional == false ) :
315- let arrayValue = tupleValue as! Array < String >
316- print ( " \( tabs ( ) ) internal let \( tupleKey. lowercaseFirst ( ) ) : \( type) = \( arrayValue) " )
312+ if let arrayValue = tupleValue as? Array < String > {
313+ print ( " \( tabs ( ) ) internal let \( tupleKey. lowercaseFirst ( ) ) : \( type) = \( arrayValue) " )
314+ }
317315 case " Array<Any> " where ( isOptional == true ) :
318- let arrayValue = tupleValue as! Array < String >
319- print ( " \( tabs ( ) ) internal var \( tupleKey. lowercaseFirst ( ) ) : \( type) ? = \( arrayValue) " )
316+ if let arrayValue = tupleValue as? Array < String > {
317+ print ( " \( tabs ( ) ) internal var \( tupleKey. lowercaseFirst ( ) ) : \( type) ? = \( arrayValue) " )
318+ }
320319 default :
321320 // default is a struct
322321 // Generate struct from the Dictionaries and Protocols
@@ -334,7 +333,9 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
334333 }
335334 }
336335
337- guard let key = key, let optionalKeysAndTypes = optionalDictionary [ key] else {
336+ guard
337+ let key = key,
338+ let optionalKeysAndTypes = optionalDictionary [ key] else {
338339 print ( " \( tabs ( intendBy: - 1 ) ) } \n " )
339340 return
340341 }
@@ -559,7 +560,7 @@ class KeyValueTuples {
559560// MARK: Main
560561
561562let args = CommandLine . arguments
562- var plists : [ String ] = [ ]
563+ var plists = [ String ] ( )
563564var enumName : String = " "
564565
565566if ( args. count < 4 ) {
@@ -595,11 +596,12 @@ if (args.count >= 6 && args[1] == "-e" && args[3] == "-o") {
595596let shouldGenerateOddKeys : Bool = CommandLine . arguments. count >= 5
596597var commonKeys = [ String] ( )
597598var oddKeys = [ String] ( )
598- var keysAndTypes : [ String : String ] = [ : ]
599- var allTuples : [ KeyValueTuples ] = [ ]
599+ var keysAndTypes = [ String: String] ( )
600+ var allTuples = [ KeyValueTuples ] ( )
600601var protocolName : String = enumName. appending ( " Protocol " )
601- var tuplesForPlists : [ String : KeyValueTuples ] = [ : ]
602- var allKeyValueTuples : [ String : KeyValueTuples ] = [ : ]
602+ var tuplesForPlists = [ String: KeyValueTuples] ( )
603+ var allKeyValueTuples = [ String: KeyValueTuples] ( )
604+
603605generateHeader ( )
604606
605607// gather keys and values... and types
0 commit comments