-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ac8e6
commit 43c299a
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Encodable+Helpers.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/2/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public extension Encodable { | ||
|
||
var asJsonData: Data? { | ||
let encoder = JSONEncoder(); | ||
encoder.outputFormatting = .prettyPrinted; | ||
encoder.dateEncodingStrategy = .iso8601; | ||
|
||
return try? encoder.encode(self); | ||
}; | ||
|
||
var asDictionary : [String: Any]? { | ||
guard let jsonData = self.asJsonData, | ||
let json = try? JSONSerialization.jsonObject( | ||
with: jsonData, | ||
options: [] | ||
) | ||
else { return nil }; | ||
|
||
return json as? [String: Any]; | ||
}; | ||
}; |