Skip to content

Commit dcfe0bf

Browse files
committed
nits
1 parent f0469e0 commit dcfe0bf

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Sources/ParseSwift/Types/ParsePushPayload/Apple/ParsePushPayloadApple.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ public struct ParsePushPayloadApple: ParsePushApplePayloadable {
116116

117117
public init(from decoder: Decoder) throws {
118118
let values = try decoder.container(keyedBy: CodingKeys.self)
119+
do {
120+
alert = try values.decode(ParsePushAppleAlert.self, forKey: .alert)
121+
} catch {
122+
if let alertBody = try values.decodeIfPresent(String.self, forKey: .alert) {
123+
alert = ParsePushAppleAlert(body: alertBody)
124+
}
125+
}
119126
relevanceScore = try values.decodeIfPresent(Double.self, forKey: .relevanceScore)
120127
targetContentId = try values.decodeIfPresent(String.self, forKey: .targetContentId)
121128
mutableContent = try values.decodeIfPresent(Int.self, forKey: .mutableContent)
@@ -131,14 +138,6 @@ public struct ParsePushPayloadApple: ParsePushApplePayloadable {
131138
topic = try values.decodeIfPresent(String.self, forKey: .topic)
132139
interruptionLevel = try values.decodeIfPresent(String.self, forKey: .interruptionLevel)
133140
urlArgs = try values.decodeIfPresent([String].self, forKey: .urlArgs)
134-
do {
135-
alert = try values.decode(ParsePushAppleAlert.self, forKey: .alert)
136-
} catch {
137-
guard let alertBody = try values.decodeIfPresent(String.self, forKey: .alert) else {
138-
return
139-
}
140-
alert = ParsePushAppleAlert(body: alertBody)
141-
}
142141
}
143142

144143
/**

Tests/ParseSwiftTests/ParsePushPayloadAppleTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class ParsePushPayloadAppleTests: XCTestCase {
128128
let anyEncodablePayload = AnyEncodable(applePayload)
129129
let anyEncodablePayload2 = AnyEncodable(decoded)
130130
XCTAssertEqual(anyEncodablePayload, anyEncodablePayload2)
131+
let value = "peace"
132+
let dictionary = [anyEncodablePayload: value]
133+
XCTAssertEqual(dictionary[anyEncodablePayload2], value)
131134
}
132135

133136
func testAppleAlertStringDecode() throws {

0 commit comments

Comments
 (0)