mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Prototype response to app
This commit is contained in:
parent
175e642081
commit
b7725c455b
3 changed files with 41 additions and 13 deletions
|
@ -6,18 +6,31 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import RealmSwift
|
||||
|
||||
extension String: Error {}
|
||||
|
||||
typealias Dictionaryable = Encodable
|
||||
|
||||
extension Encodable {
|
||||
func asDictionary() throws -> [String: Any] {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw NSError()
|
||||
func asDictionary() throws -> [String: Any] {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw NSError()
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection where Iterator.Element: Encodable {
|
||||
func asDictionaryArray() throws -> [[String: Any]] {
|
||||
return try self.enumerated().map() {
|
||||
i, element -> [String: Any] in try element.asDictionary()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DispatchQueue {
|
||||
static func runOnMainQueue(callback: @escaping (() -> Void)) {
|
||||
if Thread.isMainThread {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue