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

Relax the requirement that an object must already exist in local storage for Codable types. #31

Closed mrlegowatch closed 2 months ago

mrlegowatch commented 3 months ago

Due to a limitation in how an Objective-C compatible throwable method can be declared, the return type must be non-optional, so that the Objective-C runtime can return nil when an error is thrown. This limitation was incorporated into the Objective-C version of the retrieveObject method, but because the test to throw the error was deep inside the implementation, it also propagated to the Swift MappableObject version of the retrieveObject method and the Swift-only Codable retrieve methods, even though those could already support returning nil.

This MR relaxes the constraint on the Codable retrieve methods and Swift MappableObject retrieveObject method, so that nil can be returned without requiring throwing an error "object not found". The test to throw the error was moved to the Objective-C-only version of the retrieveObject method.

Test points were added for all three functions to illustrate the difference.

bobgilmore commented 2 months ago

Looks good as-is!