Skip to content

Commit 2460ed0

Browse files
committed
Remove ofType
1 parent a4b6058 commit 2460ed0

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

README.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ try? storage.setObject(data, forKey: "a bunch of bytes")
190190
try? storage.setObject(authorizeURL, forKey: "authorization URL")
191191

192192
// Load from storage
193-
let score = try? storage.object(ofType: Int.self, forKey: "score")
194-
let favoriteCharacter = try? storage.object(ofType: String.self, forKey: "my favorite city")
193+
let score = try? storage.object(=forKey: "score")
194+
let favoriteCharacter = try? storage.object(forKey: "my favorite city")
195195

196196
// Check if an object exists
197-
let hasFavoriteCharacter = try? storage.existsObject(ofType: String.self, forKey: "my favorite city")
197+
let hasFavoriteCharacter = try? storage.existsObject(forKey: "my favorite city")
198198

199199
// Remove an object in storage
200200
try? storage.removeObject(forKey: "my favorite city")
@@ -211,7 +211,7 @@ try? storage.removeExpiredObjects()
211211
There is time you want to get object together with its expiry information and meta data. You can use `Entry`
212212

213213
```swift
214-
let entry = try? storage.entry(ofType: String.self, forKey: "my favorite city")
214+
let entry = try? storage.entry(forKey: "my favorite city")
215215
print(entry?.object)
216216
print(entry?.expiry)
217217
print(entry?.meta)
@@ -249,7 +249,7 @@ storage.async.setObject("Oslo", forKey: "my favorite city") { result in
249249
}
250250
}
251251

252-
storage.async.object(ofType: String.self, forKey: "my favorite city") { result in
252+
storage.async.object(forKey: "my favorite city") { result in
253253
switch result {
254254
case .value(let city):
255255
print("my favorite city is \(city)")
@@ -258,7 +258,7 @@ storage.async.object(ofType: String.self, forKey: "my favorite city") { result i
258258
}
259259
}
260260

261-
storage.async.existsObject(ofType: String.self, forKey: "my favorite city") { result in
261+
storage.async.existsObject(forKey: "my favorite city") { result in
262262
if case .value(let exists) = result, exists {
263263
print("I have a favorite city")
264264
}
@@ -302,19 +302,6 @@ try? storage.setObject(
302302
storage.removeExpiredObjects()
303303
```
304304

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-
318305
## Handling JSON response
319306

320307
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

Comments
 (0)