File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -780,8 +780,10 @@ extension JSON {
780
780
}
781
781
}
782
782
public func exists( ) -> Bool {
783
- if let errorValue = error , errorValue. code == ErrorNotExist{
784
- return false
783
+ if let errorValue = error, errorValue. code == ErrorNotExist ||
784
+ errorValue. code == ErrorIndexOutOfBounds ||
785
+ errorValue. code == ErrorWrongType {
786
+ return false
785
787
}
786
788
return true
787
789
}
Original file line number Diff line number Diff line change @@ -214,7 +214,14 @@ class BaseTests: XCTestCase {
214
214
let dictionary = [ " number " : 1111 ]
215
215
let json = JSON ( dictionary)
216
216
XCTAssertFalse ( json [ " unspecifiedValue " ] . exists ( ) )
217
+ XCTAssertFalse ( json [ 0 ] . exists ( ) )
217
218
XCTAssertTrue ( json [ " number " ] . exists ( ) )
219
+
220
+ let array = [ [ " number " : 1111 ] ]
221
+ let jsonForArray = JSON ( array)
222
+ XCTAssertTrue ( jsonForArray [ 0 ] . exists ( ) )
223
+ XCTAssertFalse ( jsonForArray [ 1 ] . exists ( ) )
224
+ XCTAssertFalse ( jsonForArray [ " someValue " ] . exists ( ) )
218
225
}
219
226
220
227
func testErrorHandle( ) {
You can’t perform that action at this time.
0 commit comments