Ferrite/Ferrite/Utils/CodableWrapper.swift
kingbri 6e95c6072c Settings: Fix Default actions and Kodi
Fix how default actions are picked and add in default app actions
as options for both debrid and magnet defaults. Kodi shows the
action choice sheet with the DisclosureGroup dropped down.

The new Kodi server framework also wasn't implemented in the Kodi
wrapper. Fix that.

Finally, add some iOS 14 fixes and repair the autocorrect search
setting to actually work.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-03-21 13:56:09 -04:00

36 lines
894 B
Swift

//
// CodableWrapper.swift
// Ferrite
//
// Created by Brian Dashore on 3/20/23.
//
// From https://forums.swift.org/t/rawrepresentable-conformance-leads-to-crash/51912/4
// Prevents recursion when using Codable with RawRepresentable without needing manual conformance
import Foundation
struct CodableWrapper<Value: Codable> {
var value: Value
}
extension CodableWrapper: RawRepresentable {
var rawValue: String {
guard
let data = try? JSONEncoder().encode(value),
let string = String(data: data, encoding: .utf8)
else {
return ""
}
return string
}
init?(rawValue: String) {
guard
let data = rawValue.data(using: .utf8),
let decoded = try? JSONDecoder().decode(Value.self, from: data)
else {
return nil
}
value = decoded
}
}