Skip to content

Commit

Permalink
Create Any? property for nullable/any attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Smith committed Nov 23, 2016
1 parent 1c162a0 commit 873d7fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion json2swift/swift-code-generation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ internal extension TransformationFromJSON {

private static func letStatementForPrimitiveValue(_ attributeName: String, _ propertyName: String, _ type: SwiftPrimitiveValueType) -> LineOfCode {
switch type {
case .any: return "let \(propertyName) = json[\"\(attributeName)\"] as? [Any?]" // Any is treated as optional.
case .any: return "let \(propertyName) = json[\"\(attributeName)\"] as? Any" // Any is treated as optional.
case .bool, .int, .string: return "let \(propertyName) = json[\"\(attributeName)\"] as? \(type.name)"
case .double: return "let \(propertyName) = Double(json: json, key: \"\(attributeName)\")" // Allows an integer to be interpreted as a double.
case .url: return "let \(propertyName) = URL(json: json, key: \"\(attributeName)\")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest
class swift_code_generation_primitive_value_tests: XCTestCase {
func test_any() {
let transformation = TransformationFromJSON.toPrimitiveValue(attributeName: "a", propertyName: "p", type: .any)
XCTAssertEqual(transformation.letStatement, "let p = json[\"a\"] as? [Any?]")
XCTAssertEqual(transformation.letStatement, "let p = json[\"a\"] as? Any")
}

func test_bool() {
Expand Down

0 comments on commit 873d7fb

Please sign in to comment.