Skip to content
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

Remove public RawRepresentable conformances #219

Merged
merged 2 commits into from
Aug 26, 2024
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
34 changes: 17 additions & 17 deletions Sources/Turf/JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ extension JSONValue: RawRepresentable {
/// can succeed when the NSNumber's value is 0 or 1 even
/// when its objCType is not 'c'.
self = .boolean(boolean)
} else if let rawArray = rawValue as? JSONArray.RawValue,
let array = JSONArray(rawValue: rawArray) {
} else if let rawArray = rawValue as? JSONArray.TurfRawValue,
let array = JSONArray(turfRawValue: rawArray) {
self = .array(array)
} else if let rawObject = rawValue as? JSONObject.RawValue,
let object = JSONObject(rawValue: rawObject) {
} else if let rawObject = rawValue as? JSONObject.TurfRawValue,
let object = JSONObject(turfRawValue: rawObject) {
self = .object(object)
} else {
return nil
Expand All @@ -123,9 +123,9 @@ extension JSONValue: RawRepresentable {
case let .number(value):
return value
case let .object(value):
return value.rawValue
return value.turfRawValue
case let .array(value):
return value.rawValue
return value.turfRawValue
}
}
}
Expand All @@ -135,14 +135,14 @@ extension JSONValue: RawRepresentable {
*/
public typealias JSONArray = [JSONValue?]

extension JSONArray: RawRepresentable {
public typealias RawValue = [Any?]
public init?(rawValue values: RawValue) {
extension JSONArray {
public typealias TurfRawValue = [Any?]

public init?(turfRawValue values: TurfRawValue) {
self = values.map(JSONValue.init(rawValue:))
}
public var rawValue: RawValue {

public var turfRawValue: TurfRawValue {
return map { $0?.rawValue }
}
}
Expand All @@ -152,14 +152,14 @@ extension JSONArray: RawRepresentable {
*/
public typealias JSONObject = [String: JSONValue?]

extension JSONObject: RawRepresentable {
public typealias RawValue = [String: Any?]
extension JSONObject {
public typealias TurfRawValue = [String: Any?]

public init?(rawValue: RawValue) {
self = rawValue.mapValues { $0.flatMap(JSONValue.init(rawValue:)) }
public init?(turfRawValue: TurfRawValue) {
self = turfRawValue.mapValues { $0.flatMap(JSONValue.init(rawValue:)) }
}

public var rawValue: RawValue {
public var turfRawValue: TurfRawValue {
return mapValues { $0?.rawValue }
}
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/TurfTests/JSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class JSONTests: XCTestCase {

XCTAssertNil(JSONValue(rawValue: NSNull()))
XCTAssertEqual(JSONValue(rawValue: [NSNull()]), .array([nil]))
XCTAssertEqual(JSONArray(rawValue: [NSNull()]), [nil])
XCTAssertEqual(JSONArray(turfRawValue: [NSNull()]), [nil])
XCTAssertEqual(JSONValue(rawValue: ["NSNull": NSNull()]), .object(["NSNull": nil]))
XCTAssertEqual(JSONObject(rawValue: ["NSNull": NSNull()]), ["NSNull": nil])
XCTAssertEqual(JSONObject(turfRawValue: ["NSNull": NSNull()]), ["NSNull": nil])

XCTAssertNil(JSONValue(rawValue: Set(["Get"])))
XCTAssertEqual(JSONValue(rawValue: [Set(["Get"])]), .array([nil]))
XCTAssertEqual(JSONArray(rawValue: [Set(["Get"])]), [nil])
XCTAssertEqual(JSONArray(turfRawValue: [Set(["Get"])]), [nil])
XCTAssertEqual(JSONValue(rawValue: ["set": Set(["Get"])]), .object(["set": nil]))
XCTAssertEqual(JSONObject(rawValue: ["set": Set(["Get"])]), ["set": nil])
XCTAssertEqual(JSONObject(turfRawValue: ["set": Set(["Get"])]), ["set": nil])
}

func testLiterals() throws {
Expand Down
4 changes: 2 additions & 2 deletions Turf.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Sources/Turf/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -581,7 +581,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Sources/Turf/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos appletvsimulator watchsimulator watchos";
Expand Down