AutoCat2/AutoCatCore/Extensions/RealmDecoding.swift

17 lines
428 B
Swift

//
// RealmDecoding.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 12.02.2023.
//
import RealmSwift
extension KeyedDecodingContainer {
func decode<T: Decodable>(_ type: Persisted<List<T>>.Type, forKey key: Key) throws -> Persisted<List<T>> {
// Use decode if present, falling back to an empty list
try decodeIfPresent(type, forKey: key) ?? Persisted<List<T>>(wrappedValue: List<T>())
}
}