Last active
January 14, 2023 19:07
-
-
Save ricardopsantos/6858fe4d7094c79894c5d623055cd66d to your computer and use it in GitHub Desktop.
Article_13_G4.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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