XRepository: lightweight implementation of Repository pattern in Swift

Related tags

Regex XRepository
Overview


Supported Platforms: iOS, macOS, tvOS, watchOS

XRepository is based on QBRepository by QuickBirds Studios. It is lightweight implementation of Repository pattern in Swift.

👋🏻 Getting started

Cornerstones of this project are protocol Repository and class AnyRepository as its generic implementation. Repository supports basic and advanced CRUD operations. Also, you have access to out-of-the-box implementations of a few popular storages based on: UserDefaults, RealmSwift, FileManager, CoreData. But you can also create your own implementation of those ones or any other storage mechanism.

public protocol Repository {
  associatedtype Model
  ...
}

public final class AnyRepository<Model>: Repository {
  ...
}

🔧 Usage

Since Repository requires associated value to it, we use its generic implementation AnyRepository. Usage is simple:

class ChurchesViewModel {
  ...  
  init(_ churchesRepository: AnyRepository<Church>) {
  
    let localChurch = Church(id: "hillsong-lviv", name: "Hillsong Lviv", family: "hillsong-family")
    let stateChurches = [Church(id: "hillsong-lviv", name: "Hillsong Lviv", family: "hillsong-family"), Church(id: "hillsong-odesa", name: "Hillsong Odesa", family: "hillsong-family")]
    
    // Create
    churchesRepository.create(localChurch)
    churchesRepository.create(stateChurches)
    
    // Read
    let allChurches = churchesRepository.getAll()
    let hillsongChurch = churches.getElement(withId: "hillsong")
    let hillsongFamilyChurches = churches.getElements(filterBy: \.family == "hillsong")
    
    // Update
    churchesRepository.update(Church(id: "hillsong", name: "Hillsong Kyiv", family: "hillsong-family"))
    
    // Delete
    churchesRepository.deleteAll()
    churchRepository.delete(localChurch)
    churchRepository.delete(stateChurches)
  }
  ...
}

let churchesUserDefaultsStorage = UserDefaultsRepository<Church>()
let churchesRealmStorage = RealmRepository<Church>()
let churchesCoreDataStorage = CoreDataRepository<Church>()
let churchesFileSystemStorage = FileSystemRepository<Church>()

// Any repository will fit
let churchesViewModel = ChurchesViewModel(churchesRepository: AnyRepository(churchesRealmStorage))

⚡️ Rx

XRepository supports reactive wrapper over AnyRepository

let churchesRepository: AnyRepository<Church>!

churchesRepository.rx.getElements(sortedBy: \.name)
  .subscribe(onNext: { churchesOrderedByName in
    ...
  })
  .disposed(by: bag)

If you want a pure reactive repository implementations for popular storages, check my latest project: ReactiveXRepository

🍴 Instalation

Swift Package Manager

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 Alamofire does support its use on supported platforms.

Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/sashkopotapov/XRepository.git", .upToNextMajor(from: "1.0.0"))
]

👤 Author

This framework is created by Sashko Potapov.

📃 License

XCoordinator is released under an MIT license. See License.md for more information.

You might also like...
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

AsyncDispatcher is a lightweight Dispatcher implementation of Flux pattern.
AsyncDispatcher is a lightweight Dispatcher implementation of Flux pattern.

Simplified Dispatcher implementation of Flux pattern written in Swift using new async/await concurrency model

RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

A beautiful and flexible text field control implementation of
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

A beautiful and flexible text field control implementation of
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.

TopicEventBus Publish–subscribe design pattern implementation framework, with ability to publish events by topic. (NotificationCenter extended alterna

An extremely lean implementation on the classic iOS router pattern.
An extremely lean implementation on the classic iOS router pattern.

Beeline is a very small library that aims to provide a lean, automatic implementation of the classic iOS router pattern.

Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.

TopicEventBus Publish–subscribe design pattern implementation framework, with ability to publish events by topic. (NotificationCenter extended alterna

When is a lightweight implementation of Promises in Swift
When is a lightweight implementation of Promises in Swift

Description When is a lightweight implementation of Promises in Swift. It doesn't include any helper functions for iOS and OSX and it's intentional, t

When is a lightweight implementation of Promises in Swift.
When is a lightweight implementation of Promises in Swift.

Description When is a lightweight implementation of Promises in Swift. It doesn't include any helper functions for iOS and OSX and it's intentional, t

📬 A lightweight implementation of an observable sequence that you can subscribe to.
📬 A lightweight implementation of an observable sequence that you can subscribe to.

Features Lightweight Observable is a simple implementation of an observable sequence that you can subscribe to. The framework is designed to be minima

📬 A lightweight implementation of an observable sequence that you can subscribe to.
📬 A lightweight implementation of an observable sequence that you can subscribe to.

Features Lightweight Observable is a simple implementation of an observable sequence that you can subscribe to. The framework is designed to be minima

Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift.

100DaysOfSwift 📱 Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift. Days 1-12: Introd

Swift-flows - Simplistic hot and cold flow-based reactive observer pattern for Swift… ideal for MVVM architectures

SwiftFlows Simplistic hot and cold flow-based reactive observer pattern for Swif

A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern

Locatable Context Locatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom att

This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD
This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD

Apress Source Code This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD by Gio Lodi (Apress, 2021). D

This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package.

This repository hosts the PushwooshGeozones iOS SDK as an XCFramework based Swift Package. Use this repository's Swift Package in Xcode 12+

Swift iOS coffee ordering app that uses the MVVM design pattern that makes
Swift iOS coffee ordering app that uses the MVVM design pattern that makes

CoffeeOrder Swift iOS coffee ordering app that uses the MVVM design pattern that makes "GET" and "POST" requests to an API for the orders Screenshots

This is MVP pattern testing with Swift.
This is MVP pattern testing with Swift.

sample-swift-mvp MVP 패턴에 대한 이해를 높이기 위해서 샘플 코드 작성 및 기록 MVP 패턴 MVP(Model-View-Presenter) 패턴은 소프트웨어 아키텍처 패턴이다 M (Model) - 데이터 모델 - 실질적인 데이터 V (View) - M

Releases(1.2.0)
  • 1.2.0(Mar 15, 2022)

    Removed UserDefaults repository since it is quite strange storage and added BufferRepository - super lightweight in-memory storage based on RxRelay to make it work smoothly with RxXRepository extension.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Dec 19, 2021)

  • 1.0.0(Dec 17, 2021)

Owner
Sashko Potapov
Software Engineer with deep interest in RFP and Blockchain.
Sashko Potapov
This is a repo for my implementation of Gang of Four Book: Software Design Patterns. All written in Swift.

GoF-Swift-Design-Patterns This repo is intended to implement the known Software Design Patterns from the Gang of Four book using Swift Programming Lan

Noor El-Din Walid 3 Jul 11, 2022
A delightful and expressive regular expression type for Swift.

Regex Pattern match like a boss. Usage Create: // Use `Regex.init(_:)` to build a regex from a static pattern let greeting = Regex("hello (world|univ

Adam Sharp 612 Dec 17, 2022
Perl-like regex =~ operator for Swift

SwiftRegex Perl-like regex =~ operator for Swift This package implements a =~ string infix operator for use in testing regular expressions and retriev

Gregory Todd Williams 112 Oct 15, 2022
Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way. 简体中文 日本語 한국어 This is Easy import PySwiftyRegex if let m = re.search("[Tt]his is (.*?

Ce Zheng 232 Oct 12, 2022
Regular expressions for swift

Regex Advanced regular expressions for Swift Goals Regex library was mainly introduced to fulfill the needs of Swift Express - web application server

Crossroad Labs 328 Nov 20, 2022
Regex class for Swift. Wraps NSRegularExpression.

Regex.swift install Use CocoaPods. Add to your Podfile: pod 'Regex' And then run pod install from the shell: $ pod install usage Simple use cases: Str

Bryn Bellomy 67 Sep 14, 2022
Learn about how SoulverCore can give Swift "better than regex" data parsing features (for many common tasks)

String Parsing with Soulver Core A declarative & type-safe approach to parsing data from strings SoulverCore gives you human-friendly, type-safe & per

Soulver 140 Nov 23, 2022
RxXRepository: reactive extension for XRepository

RxXRepository is reactive extension for XRepository. This extension allows imple

Sashko Potapov 1 Jan 6, 2022
Mahmoud-Abdelwahab 5 Nov 23, 2022
Implementation of the repository pattern in Swift, using generics.

Store Simple, powerful and elegant implementation of the repository pattern, using generics. Why? ?? There are a couple of ways to implement the Repos

Narek Mailian 2 Aug 31, 2022