Skip to content

Commit

Permalink
- fixed a bug in Operators left behind when removing the Generic on M…
Browse files Browse the repository at this point in the history
…apper

- added a test for dictionaries of custom objects
  • Loading branch information
tristanhimmelman committed Feb 3, 2015
1 parent d53448c commit 61aa83e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ObjectMapper/Core/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public func <=<T: Mappable>(inout left: Dictionary<String, T>, right: Map) {
}

// Optional Dictionary <String, T: Mappable>
public func <=<T: Mappable, U>(inout left: Dictionary<String, T>?, right: Map) {
public func <=<T: Mappable>(inout left: Dictionary<String, T>?, right: Map) {
if right.mappingType == MappingType.fromJSON {
FromJSON<T>().optionalObjectDictionary(&left, object: right.currentValue)
} else {
Expand Down
29 changes: 29 additions & 0 deletions ObjectMapperTests/ObjectMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ class ObjectMapperTests: XCTestCase {
}
}

func testDictionaryOfCustomObjects(){
let percentage1: Double = 0.1
let percentage2: Double = 1792.41

let JSON = "{\"tasks\": { \"task1\": {\"taskId\":103,\"percentage\":\(percentage1)}, \"task2\": {\"taskId\":108,\"percentage\":\(percentage2)}}}"

let taskDict = Mapper<TaskDictionary>().map(string: JSON)
if let task = taskDict.tasks?["task1"] {
XCTAssertEqual(task.percentage!, percentage1, "Percentage 1 should be the same")
} else {
XCTAssert(false, "Dictionary not mapped")
}
}

func testDoubleParsing(){
let percentage1: Double = 1792.41

Expand Down Expand Up @@ -429,6 +443,21 @@ class Task: Mappable {
}
}

class TaskDictionary: Mappable {
var test: String?
var tasks: [String : Task]?

required init(){

}

func map(map: Map) {
test <= map["test"]
tasks <= map["tasks"]
}
}


// Confirm that struct can conform to `Mappable`
struct Student: Mappable {
var name: String?
Expand Down

0 comments on commit 61aa83e

Please sign in to comment.