i couldn't find any evidence that would suggest either way.
i'm currently creating new instances each time and configuring them with custom decoding/encoding options, and wondered if i could create a singleton and vend it each time i need it.
Judging by the code for JSONDecoder
and JSONEncoder
they seem to be thread-safe.
Both encode()
and decode()
use JSONSerialization
(which has been thread-safe since iOS 7 and macOS 10.9), and both methods create their own private decode/encode objects in local variables. There is no shared storage as far as I can see.
The code can be found here: https://github.com/apple/swift-corelibs-foundation/blob/master/Sources/Foundation/JSONEncoder.swift
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With