File tree Expand file tree Collapse file tree 2 files changed +13
-14
lines changed Expand file tree Collapse file tree 2 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ class FromJSON<CollectionType> {
8585
8686 /// Dctionary containing Mappable objects
8787 func objectDictionary< N: Mappable > ( inout field: Dictionary < String , N > , object: AnyObject ? ) {
88- let parsedObjects : Dictionary < String , N > ? = parseObjectDictionary ( object)
88+ let parsedObjects = Mapper < N > ( ) . mapDictionary ( object)
8989
9090 if let objects = parsedObjects {
9191 field = objects
@@ -94,22 +94,11 @@ class FromJSON<CollectionType> {
9494
9595 /// Optional dictionary containing Mappable objects
9696 func optionalObjectDictionary< N: Mappable > ( inout field: Dictionary < String , N > ? , object: AnyObject ? ) {
97- field = parseObjectDictionary ( object)
97+ field = Mapper < N > ( ) . mapDictionary ( object)
9898 }
9999
100100 /// Implicitly unwrapped Dictionary containing Mappable objects
101101 func optionalObjectDictionary< N: Mappable > ( inout field: Dictionary < String , N > ! , object: AnyObject ? ) {
102- field = parseObjectDictionary ( object)
103- }
104-
105- /**
106- * Parses a JSON Dictionary of dictionary into a Dictionay of Mappable objects
107- */
108- private func parseObjectDictionary< N: Mappable > ( object: AnyObject ? ) -> Dictionary < String , N > ? {
109- if let dictionary = object as? [ String : [ String : AnyObject ] ] {
110- return Mapper < N > ( ) . mapDictionary ( dictionary)
111- }
112-
113- return nil
102+ field = Mapper < N > ( ) . mapDictionary ( object)
114103 }
115104}
Original file line number Diff line number Diff line change @@ -162,6 +162,16 @@ public final class Mapper<N: Mappable> {
162162 }
163163 }
164164
165+ /// Maps a JSON object to a dictionary of Mappable objects if it is a JSON
166+ /// dictionary of dictionaries, or returns nil.
167+ public func mapDictionary( JSON: AnyObject ? ) -> [ String : N ] ? {
168+ if let JSONDictionary = JSON as? [ String : [ String : AnyObject ] ] {
169+ return mapDictionary ( JSONDictionary)
170+ }
171+
172+ return nil
173+ }
174+
165175 /**
166176 * Maps a JSON dictionary of dictionaries to a dictionary of objects that conform to Mappable.
167177 */
You can’t perform that action at this time.
0 commit comments