Skip to content

Commit

Permalink
feature: extension encodable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jihyun247 committed Jul 24, 2024
1 parent 2bddaf2 commit 7eadf98
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Projects/Shared/Utils/Sources/Extensions/Encodable+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@
//

import Foundation

extension Encodable {
public func toDictionary() throws -> [String: Any] {
guard let data = try? JSONEncoder().encode(self),
let jsonData = try? JSONSerialization.jsonObject(with: data),
let dictionaryData = jsonData as? [String: Any] else { return [:] }
return dictionaryData
}
}

0 comments on commit 7eadf98

Please sign in to comment.