Skip to content

Commit

Permalink
Merge pull request #219 from mapbox/bugfix/public-protocol-conformans
Browse files Browse the repository at this point in the history
Remove public RawRepresentable conformances
  • Loading branch information
OdNairy authored Aug 26, 2024
2 parents 9562a54 + 93eb467 commit d84bddd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
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

0 comments on commit d84bddd

Please sign in to comment.