Skip to content

Commit fc34024

Browse files
committed
improved description generator
1 parent c6e427e commit fc34024

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ extension DefaultModelFileComponent {
136136

137137
func genDescriptionForPrimitive(_ name: String, _ type: String, _ constantName: String) -> String {
138138
if type == VariableType.Bool.rawValue {
139-
return "dictionary.updateValue(\(name), forKey: \(constantName))"
139+
return "dictionary[\(constantName)] = \(name)"
140140
}
141-
return "if let value = \(name) { dictionary.updateValue(value, forKey: \(constantName)) }"
141+
return "if let value = \(name) { dictionary[\(constantName)] = value }"
142142
}
143143
func genDescriptionForPrimitiveArray(_ name: String, _ constantName: String) -> String {
144-
return "if let value = \(name) { dictionary.updateValue(value, forKey: \(constantName)) }"
144+
return "if let value = \(name) { dictionary[\(constantName)] = value }"
145145
}
146146

147147
func genDescriptionForObject(_ name: String, _ constantName: String) -> String {
148-
return "if let value = \(name) { dictionary.updateValue(value.dictionaryRepresentation(), forKey: \(constantName)) }"
148+
return "if let value = \(name) { dictionary[\(constantName)] = value.dictionaryRepresentation() }"
149149
}
150150

151151
func genDescriptionForObjectArray(_ name: String, _ constantName: String) -> String {
152-
return "if let value = \(name) { dictionary.updateValue(value.map { $0.dictionaryRepresentation() }, forKey: \(constantName)) }"
152+
return "if let value = \(name) { dictionary[\(constantName)] = value.map { $0.dictionaryRepresentation() } }"
153153
}
154154

155155
func genEncoder(_ name: String, _ type: String, _ constantName: String) -> String {

SwiftyJSONAccelerator/Templates/BaseTemplate.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public {OBJECT_KIND} {OBJECT_NAME}{EXTENDED_OBJECT_COLON}{EXTEND_FROM} {
2020
Generates description of the object in the form of a NSDictionary.
2121
- returns: A Key value pair containing all valid values in the object.
2222
*/
23-
public func dictionaryRepresentation() -> [String: AnyObject] {
24-
var dictionary: [String: AnyObject] = [:]
23+
public func dictionaryRepresentation() -> [String: Any] {
24+
var dictionary: [String: Any] = [:]
2525
{DESCRIPTION}
2626
return dictionary
2727
}

SwiftyJSONAccelerator/Templates/Library-Extension-Templates/SwiftyJSONTemplate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- parameter object: The object of either Dictionary or Array kind that was passed.
55
- returns: An initalized instance of the class.
66
*/
7-
convenience public init(object: AnyObject) {
7+
convenience public init(object: Any) {
88
self.init(json: JSON(object))
99
}
1010

SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ class ModelGeneratorTests: XCTestCase {
224224

225225
expect(baseModelFile!.component.description.count).to(equal(8))
226226
let descriptions = [
227-
"if let value = valueSeven { dictionary.updateValue(value.map { $0.dictionaryRepresentation() }, forKey: kACBaseClassValueSevenKey) }",
228-
"if let value = valueTwo { dictionary.updateValue(value, forKey: kACBaseClassValueTwoKey) }",
229-
"if let value = valueFour { dictionary.updateValue(value, forKey: kACBaseClassValueFourKey) }",
230-
"if let value = valueFive { dictionary.updateValue(value, forKey: kACBaseClassValueFiveKey) }",
231-
"if let value = valueSix { dictionary.updateValue(value.dictionaryRepresentation(), forKey: kACBaseClassValueSixKey) }",
232-
"if let value = valueOne { dictionary.updateValue(value, forKey: kACBaseClassValueOneKey) }",
233-
"dictionary.updateValue(valueThree, forKey: kACBaseClassValueThreeKey)",
234-
"if let value = valueEight { dictionary.updateValue(value, forKey: kACBaseClassValueEightKey) }"
227+
"if let value = valueSix { dictionary[kACBaseClassValueSixKey] = value.dictionaryRepresentation() }",
228+
"if let value = valueFive { dictionary[kACBaseClassValueFiveKey] = value }",
229+
"if let value = valueTwo { dictionary[kACBaseClassValueTwoKey] = value }",
230+
"dictionary[kACBaseClassValueThreeKey] = valueThree",
231+
"if let value = valueSeven { dictionary[kACBaseClassValueSevenKey] = value.map { $0.dictionaryRepresentation() } }",
232+
"if let value = valueOne { dictionary[kACBaseClassValueOneKey] = value }",
233+
"if let value = valueFour { dictionary[kACBaseClassValueFourKey] = value }",
234+
"if let value = valueEight { dictionary[kACBaseClassValueEightKey] = value }"
235235
]
236236
for description in descriptions {
237237
expect(baseModelFile!.component.description.contains(description)).to(equal(true))

0 commit comments

Comments
 (0)