Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created May 28, 2019 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/f70ca3818b08fa48d8d8c021031924d2 to your computer and use it in GitHub Desktop.
Save fitomad/f70ca3818b08fa48d8d8c021031924d2 to your computer and use it in GitHub Desktop.
// Creamos la cache
let cache = QuotesCache()
if let citaData = "Esto es una prueba de NSCache".data(using: .utf8)
{
// Añadimos un valor
cache.add(citaData, forKey: "Me")
// Y lo recuperamos
if let resultado = cache["Me"], let cita = String(data: resultado, encoding: .utf8)
{
print(cita)
}
cache.removeItem(forKey: "Me")
// Y lo recuperamos
if let _ = cache["Me"]
{
print("No se ha borrado la entrada")
}
else
{
print("Ha desaparecido de la cache")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment