You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is time you want to get object together with its expiry information and meta data. You can use `Entry`
212
212
213
213
```swift
214
-
let entry =try? storage.entry(ofType: String.self, forKey: "my favorite city")
214
+
let entry =try? storage.entry(forKey: "my favorite city")
215
215
print(entry?.object)
216
216
print(entry?.expiry)
217
217
print(entry?.meta)
@@ -249,7 +249,7 @@ storage.async.setObject("Oslo", forKey: "my favorite city") { result in
249
249
}
250
250
}
251
251
252
-
storage.async.object(ofType: String.self, forKey: "my favorite city") { result in
252
+
storage.async.object(forKey: "my favorite city") { result in
253
253
switch result {
254
254
case .value(let city):
255
255
print("my favorite city is \(city)")
@@ -258,7 +258,7 @@ storage.async.object(ofType: String.self, forKey: "my favorite city") { result i
258
258
}
259
259
}
260
260
261
-
storage.async.existsObject(ofType: String.self, forKey: "my favorite city") { result in
261
+
storage.async.existsObject(forKey: "my favorite city") { result in
262
262
ifcase .value(let exists) = result, exists {
263
263
print("I have a favorite city")
264
264
}
@@ -302,19 +302,6 @@ try? storage.setObject(
302
302
storage.removeExpiredObjects()
303
303
```
304
304
305
-
## What about images?
306
-
307
-
As you may know, `NSImage` and `UIImage` don't conform to `Codable` by default. To make it play well with `Codable`, we introduce `ImageWrapper`, so you can save and load images like
308
-
309
-
```swift
310
-
let wrapper =ImageWrapper(image: starIconImage)
311
-
try? storage.setObject(wrapper, forKey: "star")
312
-
313
-
let icon =try? storage.object(ofType: ImageWrapper.self, forKey: "star").image
314
-
```
315
-
316
-
If you want to load image into `UIImageView` or `NSImageView`, then we also have a nice gift for you. It's called [Imaginary](https://github.com/hyperoslo/Imaginary) and uses `Cache` under the hood to make you life easier when it comes to working with remote images.
317
-
318
305
## Handling JSON response
319
306
320
307
Most of the time, our use case is to fetch some json from backend, display it while saving the json to storage for future uses. If you're using libraries like [Alamofire](https://github.com/Alamofire/Alamofire) or [Malibu](https://github.com/hyperoslo/Malibu), you mostly get json in the form of dictionary, string, or data.
0 commit comments