Skip to content

Commit ebbc30d

Browse files
committedJul 28, 2015
Use reduce to get subscript json.
1 parent 999ae83 commit ebbc30d

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed
 

‎Source/SwiftyJSON.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,7 @@ extension JSON {
314314
*/
315315
public subscript(path: [SubscriptType]) -> JSON {
316316
get {
317-
switch path.count {
318-
case 0: return JSON.null
319-
case 1: return self[sub: path[0]]
320-
default:
321-
var aPath = path; aPath.removeAtIndex(0)
322-
let nextJSON = self[sub: path[0]]
323-
return nextJSON[aPath]
324-
}
317+
return path.reduce(self) { $0[sub: $1] }
325318
}
326319
set {
327320
switch path.count {

0 commit comments

Comments
 (0)
Please sign in to comment.