From 61aa83e39622589a197e09c79b7d39d9d3e735a3 Mon Sep 17 00:00:00 2001 From: Tristan Himmelman Date: Mon, 2 Feb 2015 16:36:00 -0800 Subject: [PATCH] - fixed a bug in Operators left behind when removing the Generic on Mapper - added a test for dictionaries of custom objects --- ObjectMapper/Core/Operators.swift | 2 +- ObjectMapperTests/ObjectMapperTests.swift | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ObjectMapper/Core/Operators.swift b/ObjectMapper/Core/Operators.swift index 21077bb1..99621445 100755 --- a/ObjectMapper/Core/Operators.swift +++ b/ObjectMapper/Core/Operators.swift @@ -84,7 +84,7 @@ public func <=(inout left: Dictionary, right: Map) { } // Optional Dictionary -public func <=(inout left: Dictionary?, right: Map) { +public func <=(inout left: Dictionary?, right: Map) { if right.mappingType == MappingType.fromJSON { FromJSON().optionalObjectDictionary(&left, object: right.currentValue) } else { diff --git a/ObjectMapperTests/ObjectMapperTests.swift b/ObjectMapperTests/ObjectMapperTests.swift index 75a7e32f..37e76b7e 100644 --- a/ObjectMapperTests/ObjectMapperTests.swift +++ b/ObjectMapperTests/ObjectMapperTests.swift @@ -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().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 @@ -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?