@@ -76,70 +76,47 @@ public func <- <T: RawRepresentable>(inout left: T!, right: Map) {
7676* Array of Raw Representable object
7777*/
7878public func <- < T: RawRepresentable > ( inout left: [ T ] , right: Map ) {
79- if right. mappingType == MappingType . FromJSON {
80- FromJSON . rawRepresentableArray ( & left, object: right. value ( ) )
81- } else {
82- ToJSON . rawRepresentableArray ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
83- }
79+ left <- ( right, EnumTransform ( ) )
8480}
8581
8682/**
8783* Array of Raw Representable object
8884*/
8985public func <- < T: RawRepresentable > ( inout left: [ T ] ? , right: Map ) {
90- if right. mappingType == MappingType . FromJSON {
91- FromJSON . rawRepresentableArray ( & left, object: right. value ( ) )
92- } else {
93- ToJSON . rawRepresentableArray ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
94- }
86+ left <- ( right, EnumTransform ( ) )
9587}
9688
9789/**
9890* Array of Raw Representable object
9991*/
10092public func <- < T: RawRepresentable > ( inout left: [ T ] ! , right: Map ) {
101- if right. mappingType == MappingType . FromJSON {
102- FromJSON . rawRepresentableArray ( & left, object: right. value ( ) )
103- } else {
104- ToJSON . rawRepresentableArray ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
105- }
93+ left <- ( right, EnumTransform ( ) )
10694}
10795
10896// MARK:- Dictionaries of Raw Representable type
10997/**
11098* Dictionary of Raw Representable object
11199*/
112100public func <- < T: RawRepresentable > ( inout left: [ String : T ] , right: Map ) {
113- if right. mappingType == MappingType . FromJSON {
114- FromJSON . rawRepresentableDict ( & left, object: right. value ( ) )
115- } else {
116- ToJSON . rawRepresentableDict ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
117- }
101+ left <- ( right, EnumTransform ( ) )
118102}
119103
120104/**
121105* Dictionary of Raw Representable object
122106*/
123107public func <- < T: RawRepresentable > ( inout left: [ String : T ] ? , right: Map ) {
124- if right. mappingType == MappingType . FromJSON {
125- FromJSON . rawRepresentableDict ( & left, object: right. value ( ) )
126- } else {
127- ToJSON . rawRepresentableDict ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
128- }
108+ left <- ( right, EnumTransform ( ) )
129109}
130110
131111/**
132112* Dictionary of Raw Representable object
133113*/
134114public func <- < T: RawRepresentable > ( inout left: [ String : T ] ! , right: Map ) {
135- if right. mappingType == MappingType . FromJSON {
136- FromJSON . rawRepresentableDict ( & left, object: right. value ( ) )
137- } else {
138- ToJSON . rawRepresentableDict ( left, key: right. currentKey!, dictionary: & right. JSONDictionary)
139- }
115+ left <- ( right, EnumTransform ( ) )
140116}
141117
142118// MARK:- Transforms
119+
143120/**
144121* Object of Basic type with Transform
145122*/
@@ -179,6 +156,110 @@ public func <- <T, Transform: TransformType where Transform.Object == T>(inout l
179156 }
180157}
181158
159+ /// Array of Basic type with Transform
160+ public func <- < T: TransformType > ( inout left: [ T . Object ] , right: ( Map , T ) ) {
161+ let ( map, transform) = right
162+ if map. mappingType == MappingType . FromJSON {
163+ let values = fromJSONArrayWithTransform ( map. currentValue, transform)
164+ FromJSON . basicType ( & left, object: values)
165+ } else {
166+ let values = toJSONArrayWithTransform ( left, transform)
167+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
168+ }
169+ }
170+
171+ /// Optional array of Basic type with Transform
172+ public func <- < T: TransformType > ( inout left: [ T . Object ] ? , right: ( Map , T ) ) {
173+ let ( map, transform) = right
174+ if map. mappingType == MappingType . FromJSON {
175+ let values = fromJSONArrayWithTransform ( map. currentValue, transform)
176+ FromJSON . optionalBasicType ( & left, object: values)
177+ } else {
178+ let values = toJSONArrayWithTransform ( left, transform)
179+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
180+ }
181+ }
182+
183+ /// Implicitly unwrapped optional array of Basic type with Transform
184+ public func <- < T: TransformType > ( inout left: [ T . Object ] ! , right: ( Map , T ) ) {
185+ let ( map, transform) = right
186+ if map. mappingType == MappingType . FromJSON {
187+ let values = fromJSONArrayWithTransform ( map. currentValue, transform)
188+ FromJSON . optionalBasicType ( & left, object: values)
189+ } else {
190+ let values = toJSONArrayWithTransform ( left, transform)
191+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
192+ }
193+ }
194+
195+ /// Dictionary of Basic type with Transform
196+ public func <- < T: TransformType > ( inout left: [ String : T . Object ] , right: ( Map , T ) ) {
197+ let ( map, transform) = right
198+ if map. mappingType == MappingType . FromJSON {
199+ let values = fromJSONDictionaryWithTransform ( map. currentValue, transform)
200+ FromJSON . basicType ( & left, object: values)
201+ } else {
202+ let values = toJSONDictionaryWithTransform ( left, transform)
203+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
204+ }
205+ }
206+
207+ /// Optional dictionary of Basic type with Transform
208+ public func <- < T: TransformType > ( inout left: [ String : T . Object ] ? , right: ( Map , T ) ) {
209+ let ( map, transform) = right
210+ if map. mappingType == MappingType . FromJSON {
211+ let values = fromJSONDictionaryWithTransform ( map. currentValue, transform)
212+ FromJSON . optionalBasicType ( & left, object: values)
213+ } else {
214+ let values = toJSONDictionaryWithTransform ( left, transform)
215+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
216+ }
217+ }
218+
219+ /// Implicitly unwrapped optional dictionary of Basic type with Transform
220+ public func <- < T: TransformType > ( inout left: [ String : T . Object ] ! , right: ( Map , T ) ) {
221+ let ( map, transform) = right
222+ if map. mappingType == MappingType . FromJSON {
223+ let values = fromJSONDictionaryWithTransform ( map. currentValue, transform)
224+ FromJSON . optionalBasicType ( & left, object: values)
225+ } else {
226+ let values = toJSONDictionaryWithTransform ( left, transform)
227+ ToJSON . optionalBasicType ( values, key: map. currentKey!, dictionary: & map. JSONDictionary)
228+ }
229+ }
230+
231+ private func fromJSONArrayWithTransform< T: TransformType > ( input: AnyObject ? , transform: T ) -> [ T . Object ] {
232+ if let values = input as? [ AnyObject ] {
233+ return values. filterMap { value in
234+ return transform. transformFromJSON ( value)
235+ }
236+ } else {
237+ return [ ]
238+ }
239+ }
240+
241+ private func fromJSONDictionaryWithTransform< T: TransformType > ( input: AnyObject ? , transform: T ) -> [ String : T . Object ] {
242+ if let values = input as? [ String : AnyObject ] {
243+ return values. filterMap { value in
244+ return transform. transformFromJSON ( value)
245+ }
246+ } else {
247+ return [ : ]
248+ }
249+ }
250+
251+ private func toJSONArrayWithTransform< T: TransformType > ( input: [ T . Object ] ? , transform: T ) -> [ T . JSON ] ? {
252+ return input? . filterMap { value in
253+ return transform. transformToJSON ( value)
254+ }
255+ }
256+
257+ private func toJSONDictionaryWithTransform< T: TransformType > ( input: [ String : T . Object ] ? , transform: T ) -> [ String : T . JSON ] ? {
258+ return input? . filterMap { value in
259+ return transform. transformToJSON ( value)
260+ }
261+ }
262+
182263// MARK:- Mappable Objects - <T: Mappable>
183264/**
184265* Object conforming to Mappable
0 commit comments