Cache icon indicating copy to clipboard operation
Cache copied to clipboard

Problem async, transformCodable and generic

Open gchablowski opened this issue 4 years ago • 1 comments

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.

gchablowski avatar Apr 30 '21 13:04 gchablowski

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

007-Heroa avatar Aug 12 '21 03:08 007-Heroa

Closing, reason outdated issue.

3lvis avatar Mar 26 '24 05:03 3lvis