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.
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:
Every time that I tried it, it gives me a
deallocated
error. It works if I put out theasync
. Moreover, It works if I put out the generic and keep theasync
. (meaning, I do something likeself._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.