mrlegowatch / GarageStorageSwift

A Swift implementation of GarageStorage. Provides a convenient way to store any kind of data in a repository backed by Core Data.
MIT License
8 stars 1 forks source link

Change retrieve to support returning nil, instead of throwing an error #28

Closed mrlegowatch closed 2 months ago

mrlegowatch commented 3 months ago

The original ObjC design of singular retrieveObject supported returning nil if the object was not found, or an error, if, for example, decryption failed. The initial Swift 1.0.0 implementation sided with returning an error "object not found" instead of nil, which proved not as useful an implementation, since an object not yet saved will always initially be nil in the Garage.

mrlegowatch commented 3 months ago

Hmm. I'm stuck on how to overcome the Objective-C-compatible retrieveObject() implementation's requirement for a non-nil return value, the compiler complains that it can't allow throwing and returning an optional, because Objective-C treats nil as an error. I am able to apply a fix for Swift retrieve<T>(). Added unit tests to convey this difference in behavior.