The simplest approach, especially with an existing system, is to create a new Repository implementation for each business object you need to store to or retrieve from your persistence layer. Further, you should only implement the specific methods you are calling in your application. Avoid the trap of creating a “standard” repository class, base class, or default interface that you must implement for all repositories. Yes, if you need to have an Update or a Delete method, you should strive to make its interface consistent (does Delete take an ID, or does it take the object itself?), but don’t implement a Delete method on your LookupTableRepository that you’re only ever going to be calling List() on. The biggest benefit of this approach is YAGNI – you won’t waste any time implementing methods that never get called.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but Repository does support its use on supported platforms.
Once you have your Swift package set up, adding Repository as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/dsay/SwiftRepository.git")
]
LocalStore
LocalStoreRealm
LocalStoreCoreData
LocalStoreCodable
LocalStoreMappable
LocalStoreFileManager
For Core Data recomended to use PersistentContainer
Dima Sai , [email protected]
Repository is available under the MIT license. See the LICENSE file for more info.