File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public protocol ConvertibleEnum {
1212 static var kk_valueType : Any . Type { get }
1313}
1414
15- extension RawRepresentable where Self: ConvertibleEnum {
15+ public extension RawRepresentable where Self: ConvertibleEnum {
1616 static func kk_convert( from value: Any ? ) -> Self ? {
1717 return ( value as? RawValue ) . flatMap { Self . init ( rawValue: $0) }
1818 }
Original file line number Diff line number Diff line change @@ -141,20 +141,16 @@ var longDecimalNumber = NSDecimalNumber(string: longDecimalString)
141141func checkModelToJSon< M: Equatable & Convertible > ( _ type: M . Type ) {
142142 // create model
143143 let model = type. init ( )
144- // get JSON from model
145- let json = model. kk. JSONObject ( )
146144 // get JSONString from model
147145 let jsonString = model. kk. JSONString ( )
148146
149147 // check JSON and JSONString
150- let modelFromJson = json? . kk. model ( anyType: type) as? M
151148 let modelFromJsonString = jsonString? . kk. model ( anyType: type) as? M
152- XCTAssert ( model == modelFromJson)
153149 XCTAssert ( model == modelFromJsonString)
154150
155- // prevent 66.6499999999999998
151+ // prevent from 66.6499999999999998
156152 XCTAssert ( jsonString? . contains ( " 99999 " ) == false )
157- // prevent 66.6600000000000001
153+ // prevent from 66.6600000000000001
158154 XCTAssert ( jsonString? . contains ( " 00000 " ) == false )
159155}
160156
Original file line number Diff line number Diff line change 77//
88
99class CompareWithCodable : XCTestCase {
10+ struct Cat : Codable {
11+ var weight : Double = 0.0
12+ var name : String = " "
13+ }
1014
15+ func test( ) {
16+ let jsonData = """
17+ {
18+ " name " : " Miaomiao " ,
19+ " weight " : 1.66
20+ }
21+ """ . data ( using: . utf8) !
22+
23+ let cat = try ! JSONDecoder ( ) . decode ( Cat . self, from: jsonData)
24+ print ( cat)
25+ }
1126}
You can’t perform that action at this time.
0 commit comments