hyperoslo / Cache

:package: Nothing but Cache.
Other
2.96k stars 335 forks source link

Problem async, transformCodable and generic #286

Closed gchablowski closed 5 months ago

gchablowski commented 3 years ago

I try to create a function with a generic to get an object in an async way. Here an example of what the function looks like:

 public func set<T: Codable>(data: T, key: String){
        let transform: Storage<String, T>? = self._storage?.transformCodable(ofType: T.self)
        transform?.async.setObject(data, forKey: key, completion: { (result) in
            switch result {
            case .value(_):
                print("done set")
                break
            case .error(let error):
                print("problem set: \(error)")
                break
            }
        })
    }

Every time that I tried it, it gives me a deallocated error. It works if I put out the async. Moreover, It works if I put out the generic and keep the async. (meaning, I do something like self._storage?.transformCodable(ofType: String.self))

I am relatively new to swift. Is it me that doesn't know how to write a generic (in those cases all my apologies), or there is a bug somewhere?

Thanks in advance for your help. And thanks for the library too.

007-Heroa commented 3 years ago

transform object is released, you need update self. _storage = transform

3lvis commented 5 months ago

Closing, reason outdated issue.