Skip to content

JSONEncoder: Rename data coding enum values to align with SE-0167 #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Foundation/JSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ open class JSONEncoder {
/// The strategy to use for encoding `Data` values.
public enum DataEncodingStrategy {
/// Encoded the `Data` as a Base64-encoded string. This is the default strategy.
case base64Encode
case base64

/// Encode the `Data` as a custom value encoded by the given closure.
///
Expand All @@ -88,8 +88,8 @@ open class JSONEncoder {
/// The strategy to use in encoding dates. Defaults to `.deferredToDate`.
open var dateEncodingStrategy: DateEncodingStrategy = .deferredToDate

/// The strategy to use in encoding binary data. Defaults to `.base64Encode`.
open var dataEncodingStrategy: DataEncodingStrategy = .base64Encode
/// The strategy to use in encoding binary data. Defaults to `.base64`.
open var dataEncodingStrategy: DataEncodingStrategy = .base64

/// The strategy to use in encoding non-conforming numbers. Defaults to `.throw`.
open var nonConformingFloatEncodingStrategy: NonConformingFloatEncodingStrategy = .throw
Expand Down Expand Up @@ -672,7 +672,7 @@ extension _JSONEncoder {

fileprivate func box(_ data: Data) throws -> NSObject {
switch self.options.dataEncodingStrategy {
case .base64Encode:
case .base64:
return NSString(string: data.base64EncodedString())

case .custom(let closure):
Expand Down Expand Up @@ -827,7 +827,7 @@ open class JSONDecoder {
/// The strategy to use for decoding `Data` values.
public enum DataDecodingStrategy {
/// Decode the `Data` from a Base64-encoded string. This is the default strategy.
case base64Decode
case base64

/// Decode the `Data` as a custom value decoded by the given closure.
case custom((_ decoder: Decoder) throws -> Data)
Expand All @@ -845,8 +845,8 @@ open class JSONDecoder {
/// The strategy to use in decoding dates. Defaults to `.deferredToDate`.
open var dateDecodingStrategy: DateDecodingStrategy = .deferredToDate

/// The strategy to use in decoding binary data. Defaults to `.base64Decode`.
open var dataDecodingStrategy: DataDecodingStrategy = .base64Decode
/// The strategy to use in decoding binary data. Defaults to `.base64`.
open var dataDecodingStrategy: DataDecodingStrategy = .base64

/// The strategy to use in decoding non-conforming numbers. Defaults to `.throw`.
open var nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy = .throw
Expand Down Expand Up @@ -2042,7 +2042,7 @@ extension _JSONDecoder {
guard !(value is NSNull) else { return nil }

switch self.options.dataDecodingStrategy {
case .base64Decode:
case .base64:
guard let string = value as? String else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestJSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ class TestJSONEncoder : XCTestCase {
outputFormatting: JSONEncoder.OutputFormatting = [],
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate,
dataEncodingStrategy: JSONEncoder.DataEncodingStrategy = .base64Encode,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .base64Decode,
dataEncodingStrategy: JSONEncoder.DataEncodingStrategy = .base64,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .base64,
nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy = .throw,
nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy = .throw) where T : Codable, T : Equatable {
var payload: Data! = nil
Expand Down