react-native-ios-context-menu/ios/src_library/Extensions/Encodable+Helpers.swift
Dominic Go ff8ec7d7f2 ⚙️ Refactored RCTContextMenuView and Related Files
Summary: Fixed so the imported files will build
/run in Xcode by adding availability checks
2020-10-22 13:12:05 +08:00

40 lines
772 B
Swift

//
// Encodable+Helpers.swift
// nativeUIModulesTest
//
// Created by Dominic Go on 7/6/20.
//
import Foundation
struct JSON {
static let encoder = JSONEncoder();
};
extension Encodable {
subscript(key: String) -> Any? {
return dictionary[key];
};
var dictionary: [String: Any] {
return
(try? JSONSerialization.jsonObject(with: JSON.encoder.encode(self)))
as? [String: Any] ?? [:];
};
func jsonData() throws -> Data {
let encoder = JSON.encoder;
encoder.outputFormatting = .prettyPrinted;
if #available(iOS 10.0, *) {
encoder.dateEncodingStrategy = .iso8601;
} else {
encoder.dateEncodingStrategy = .millisecondsSince1970;
};
return try encoder.encode(self);
};
};