API functions to sync local progress

This commit is contained in:
ronaldheft 2022-08-12 21:58:54 -04:00
parent f4e39ec7ca
commit 8d38f3358e
5 changed files with 218 additions and 10 deletions

View file

@ -6,8 +6,8 @@
//
import Foundation
import SwiftUI
import RealmSwift
import Capacitor
extension String: Error {}
@ -31,6 +31,14 @@ extension Collection where Iterator.Element: Encodable {
}
}
extension CAPPluginCall {
func getJson<T: Decodable>(_ key: String, type: T.Type) -> T? {
guard let value = getString(key) else { return nil }
guard let valueData = value.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode(type, from: valueData)
}
}
extension DispatchQueue {
static func runOnMainQueue(callback: @escaping (() -> Void)) {
if Thread.isMainThread {