Skip to content

Commit bb55924

Browse files
authored
JSONDecoder extension (#1)
Implement a pure JSON decoder function for faster decoding
1 parent 6980939 commit bb55924

5 files changed

Lines changed: 1415 additions & 10 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Apple Platform Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
SwiftPM:
14+
name: ${{ matrix.platform }}
15+
runs-on: macos-15
16+
timeout-minutes: 30
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
platform: ['ios', 'macos', 'tvos', 'watchos', 'visionos']
21+
env:
22+
DEVELOPER_DIR: /Applications/Xcode_26.2.0.app/Contents/Developer
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Test ${{ matrix.platform }}
26+
run: |
27+
set -euo pipefail
28+
case "${{ matrix.platform }}" in
29+
ios)
30+
xcodebuild clean test -workspace . -scheme SwifterJSON -destination "platform=iOS Simulator,name=iPhone 16,OS=26.2"
31+
;;
32+
tvos)
33+
xcodebuild clean test -workspace . -scheme SwifterJSON -destination "platform=tvOS Simulator,name=Apple TV,OS=26.2"
34+
;;
35+
macos)
36+
swift test --parallel
37+
;;
38+
watchos)
39+
xcodebuild clean test -workspace . -scheme SwifterJSON -destination "platform=watchOS Simulator,name=Apple Watch Series 10 (46mm),OS=26.2"
40+
;;
41+
visionos)
42+
xcodebuild clean test -workspace . -scheme SwifterJSON -destination "platform=visionOS Simulator,name=Apple Vision Pro,OS=26.2"
43+
;;
44+
esac

Sources/JSON.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ public extension JSON {
356356
/// Returns a value of the type you specify, decoded from a JSON object.
357357
/// - Parameter type: The type of the value to decode from the supplied JSON object.
358358
/// - Parameter decoder: The JSON decoder that will convert the JSON object.
359-
func decode<T>(_: T.Type = T.self, decoder: JSONDecoder = JSONDecoder()) throws -> T where T: Decodable {
360-
try decoder.decode(T.self, from: JSONEncoder().encode(self))
359+
func decode<T: Decodable>(_: T.Type = T.self, decoder: JSONDecoder = JSONDecoder()) throws -> T {
360+
try decoder.decode(T.self, from: self)
361361
}
362362
}
363363
#endif

0 commit comments

Comments
 (0)