Skip to content

Commit

Permalink
Merge branch 'pr/119'
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Aug 29, 2016
2 parents f3f5be4 + 156a6f4 commit 883e34e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions EVReflection/EVReflectionTests/EVReflectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,30 @@ class EVReflectionTests: XCTestCase {
let b = ImLazy(json: json)
print(b)
}

func testArrayFromNotArray() {
let normal = NSDictionary(dictionary: ["bs": [["val": 1], ["val": 2]]])
print(String(normal))
let aaNormal: AA = AA(dictionary: normal)
print(String(aaNormal.toDictionary()))
XCTAssertEqual(String(normal), String(aaNormal.toDictionary()))

let abnormal = NSDictionary(dictionary: ["bs": ["val": 1]])
print(String(abnormal))
let aaAbnormal: AA = AA(dictionary: abnormal)
print(String(aaAbnormal.toDictionary()))
XCTAssertEqual(aaAbnormal.bs[0].val, 1)

let arrayDic = NSDictionary(dictionary: ["strings": ["a", "b"]])
let arrObj: ArrayObjects = ArrayObjects(dictionary: arrayDic)
print(arrObj)
XCTAssertEqual((arrayDic["strings"] as! NSArray), NSArray(array: arrObj.strings))

let arrayDic2 = NSDictionary(dictionary: ["strings": "a"])
let arrObj2: ArrayObjects = ArrayObjects(dictionary: arrayDic2)
print(arrObj2)
XCTAssertEqual(arrObj2.strings[0], "a")
}
}


Expand Down
5 changes: 5 additions & 0 deletions EVReflection/pod/EVReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ final public class EVReflection {
value = date
}
}

if !(value is NSArray) && (typeInObject ?? "").containsString("Array") {
value = NSArray(array: [value])
}

if typeInObject == "Struct" {
anyObject.setValue(value, forUndefinedKey: key)
} else {
Expand Down

0 comments on commit 883e34e

Please sign in to comment.