@@ -26,7 +26,7 @@ public protocol Convertible {
2626
2727// MARK: - Basic Conversion
2828
29- public func <-- < T, U> ( inout lhs: T ? , rhs: U ? ) throws -> T ? {
29+ public func <-- < T, U> ( inout lhs: T ? , rhs: U ? ) -> T ? {
3030 if !( lhs is NSNull ) {
3131 lhs = JSONHelper . convertToNilIfNull ( rhs) as? T
3232 } else {
@@ -35,28 +35,41 @@ public func <-- <T, U>(inout lhs: T?, rhs: U?) throws -> T? {
3535 return lhs
3636}
3737
38- public func <-- < T, U> ( inout lhs: T , rhs: U ? ) throws -> T {
38+ public func <-- < T, U> ( inout lhs: T , rhs: U ? ) -> T {
3939 var newValue : T ?
40- try newValue <-- rhs
40+ newValue <-- rhs
4141 lhs = newValue ?? lhs
4242 return lhs
4343}
4444
45- public func <-- < C: Convertible , T> ( inout lhs: C ? , rhs: T ? ) throws -> C ? {
46- lhs = try C . convertFromValue ( JSONHelper . convertToNilIfNull ( rhs) )
45+ public func <-- < C: Convertible , T> ( inout lhs: C ? , rhs: T ? ) -> C ? {
46+ lhs = nil
47+
48+ do {
49+ lhs = try C . convertFromValue ( JSONHelper . convertToNilIfNull ( rhs) )
50+ } catch ConversionError . InvalidValue {
51+ #if DEBUG
52+ print ( " Invalid value \( rhs. debugDescription) for supported type. " )
53+ #endif
54+ } catch ConversionError . UnsupportedType {
55+ #if DEBUG
56+ print ( " Unsupported type. " )
57+ #endif
58+ } catch { }
59+
4760 return lhs
4861}
4962
50- public func <-- < C: Convertible , T> ( inout lhs: C , rhs: T ? ) throws -> C {
63+ public func <-- < C: Convertible , T> ( inout lhs: C , rhs: T ? ) -> C {
5164 var newValue : C ?
52- try newValue <-- rhs
65+ newValue <-- rhs
5366 lhs = newValue ?? lhs
5467 return lhs
5568}
5669
5770// MARK: - Array Conversion
5871
59- public func <-- < C: Convertible , T> ( inout lhs: [ C ] ? , rhs: [ T ] ? ) throws -> [ C ] ? {
72+ public func <-- < C: Convertible , T> ( inout lhs: [ C ] ? , rhs: [ T ] ? ) -> [ C ] ? {
6073 guard let rhs = rhs else {
6174 lhs = nil
6275 return lhs
@@ -65,7 +78,8 @@ public func <-- <C: Convertible, T>(inout lhs: [C]?, rhs: [T]?) throws -> [C]? {
6578 lhs = [ C] ( )
6679 for element in rhs {
6780 var convertedElement : C ?
68- try convertedElement <-- element
81+ convertedElement <-- element
82+
6983 if let convertedElement = convertedElement {
7084 lhs? . append ( convertedElement)
7185 }
@@ -74,36 +88,36 @@ public func <-- <C: Convertible, T>(inout lhs: [C]?, rhs: [T]?) throws -> [C]? {
7488 return lhs
7589}
7690
77- public func <-- < C: Convertible , T> ( inout lhs: [ C ] , rhs: [ T ] ? ) throws -> [ C ] {
91+ public func <-- < C: Convertible , T> ( inout lhs: [ C ] , rhs: [ T ] ? ) -> [ C ] {
7892 var newValue : [ C ] ?
79- try newValue <-- rhs
93+ newValue <-- rhs
8094 lhs = newValue ?? lhs
8195 return lhs
8296}
8397
84- public func <-- < C: Convertible , T> ( inout lhs: [ C ] ? , rhs: T ? ) throws -> [ C ] ? {
98+ public func <-- < C: Convertible , T> ( inout lhs: [ C ] ? , rhs: T ? ) -> [ C ] ? {
8599 guard let rhs = rhs else {
86100 lhs = nil
87101 return lhs
88102 }
89103
90104 if let elements = rhs as? NSArray as? [ AnyObject ] {
91- return try lhs <-- elements
105+ return lhs <-- elements
92106 }
93107
94- throw ConversionError . UnsupportedType
108+ return nil
95109}
96110
97- public func <-- < C: Convertible , T> ( inout lhs: [ C ] , rhs: T ? ) throws -> [ C ] {
111+ public func <-- < C: Convertible , T> ( inout lhs: [ C ] , rhs: T ? ) -> [ C ] {
98112 var newValue : [ C ] ?
99- try newValue <-- rhs
113+ newValue <-- rhs
100114 lhs = newValue ?? lhs
101115 return lhs
102116}
103117
104118// MARK: - Dictionary Conversion
105119
106- public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] ? , rhs: [ T : U ] ? ) throws -> [ T : C ] ? {
120+ public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] ? , rhs: [ T : U ] ? ) -> [ T : C ] ? {
107121 guard let rhs = rhs else {
108122 lhs = nil
109123 return lhs
@@ -112,7 +126,7 @@ public func <-- <T, C: Convertible, U>(inout lhs: [T : C]?, rhs: [T : U]?) throw
112126 lhs = [ T : C] ( )
113127 for (key, value) in rhs {
114128 var convertedValue : C ?
115- try convertedValue <-- value
129+ convertedValue <-- value
116130 if let convertedValue = convertedValue {
117131 lhs ? [ key] = convertedValue
118132 }
@@ -121,36 +135,36 @@ public func <-- <T, C: Convertible, U>(inout lhs: [T : C]?, rhs: [T : U]?) throw
121135 return lhs
122136}
123137
124- public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] , rhs: [ T : U ] ? ) throws -> [ T : C ] {
138+ public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] , rhs: [ T : U ] ? ) -> [ T : C ] {
125139 var newValue : [ T : C ] ?
126- try newValue <-- rhs
140+ newValue <-- rhs
127141 lhs = newValue ?? lhs
128142 return lhs
129143}
130144
131- public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] ? , rhs: U ? ) throws -> [ T : C ] ? {
145+ public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] ? , rhs: U ? ) -> [ T : C ] ? {
132146 guard let rhs = rhs else {
133147 lhs = nil
134148 return lhs
135149 }
136150
137151 if let elements = rhs as? NSDictionary as? [ T : AnyObject ] {
138- return try lhs <-- elements
152+ return lhs <-- elements
139153 }
140154
141- throw ConversionError . UnsupportedType
155+ return nil
142156}
143157
144- public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] , rhs: U ? ) throws -> [ T : C ] {
158+ public func <-- < T, C: Convertible , U> ( inout lhs: [ T : C ] , rhs: U ? ) -> [ T : C ] {
145159 var newValue : [ T : C ] ?
146- try newValue <-- rhs
160+ newValue <-- rhs
147161 lhs = newValue ?? lhs
148162 return lhs
149163}
150164
151165// MARK: - Enum Conversion
152166
153- public func <-- < T: RawRepresentable , U> ( inout lhs: T ? , rhs: U ? ) throws -> T ? {
167+ public func <-- < T: RawRepresentable , U> ( inout lhs: T ? , rhs: U ? ) -> T ? {
154168 var newValue : T ?
155169
156170 if let
@@ -163,9 +177,9 @@ public func <-- <T: RawRepresentable, U>(inout lhs: T?, rhs: U?) throws -> T? {
163177 return lhs
164178}
165179
166- public func <-- < T: RawRepresentable, U> ( inout lhs: T, rhs: U? ) throws -> T {
180+ public func <-- < T: RawRepresentable, U> ( inout lhs: T, rhs: U? ) - > T {
167181 var newValue : T ?
168- try newValue <-- rhs
182+ newValue <-- rhs
169183 lhs = newValue ?? lhs
170184 return lhs
171185}
0 commit comments