Skip to content

Instantly share code, notes, and snippets.

@ricardopsantos
Last active January 14, 2023 19:07
Show Gist options
  • Save ricardopsantos/6858fe4d7094c79894c5d623055cd66d to your computer and use it in GitHub Desktop.
Save ricardopsantos/6858fe4d7094c79894c5d623055cd66d to your computer and use it in GitHub Desktop.
Article_13_G4.swift
public extension ExpiringCodableObjectWithKey {
var isExpired: Bool { valueData == nil }
var valueData: Data? {
Self.referenceDate > expireDate ? object : nil
}
func extract<T: Codable>(_ some: T.Type) -> T? {
guard let data = valueData else {
return nil
}
return try? JSONDecoder().decode(T.self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment