Skip to content

Commit

Permalink
Fix media ID type mismatch
Browse files Browse the repository at this point in the history
This is due to Gutenberg's `replaceBlock` changing the type of the ID field.
  • Loading branch information
bjtitus committed Mar 10, 2021
1 parent 46a0740 commit ea42a67
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion WordPress/Classes/Services/Stories/StoryPoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ struct MediaFile: Codable {
}

init(dictionary: [String: Any]) throws {
// We must handle both possible types because the Gutenberg `replaceBlock` method seems to be changing the type of this field.
let id: String
do {
id = try dictionary.value(key: CodingKeys.id.stringValue, type: NSNumber.self).stringValue
} catch {
id = try dictionary.value(key: CodingKeys.id.stringValue, type: String.self)
}
self.init(alt: try dictionary.value(key: CodingKeys.alt.stringValue, type: String.self),
caption: try dictionary.value(key: CodingKeys.caption.stringValue, type: String.self),
id: try dictionary.value(key: CodingKeys.id.stringValue, type: String.self),
id: id,
link: try dictionary.value(key: CodingKeys.link.stringValue, type: String.self),
mime: try dictionary.value(key: CodingKeys.mime.stringValue, type: String.self),
type: try dictionary.value(key: CodingKeys.type.stringValue, type: String.self),
Expand Down

0 comments on commit ea42a67

Please sign in to comment.