Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ladeiko/OneWaySynchronizer
The simplest abstraction to synchronize local data with remote source. For iOS, wirtten in swift.
https://github.com/ladeiko/OneWaySynchronizer
data-synchronization ios swift
Last synced: about 1 month ago
JSON representation
The simplest abstraction to synchronize local data with remote source. For iOS, wirtten in swift.
- Host: GitHub
- URL: https://github.com/ladeiko/OneWaySynchronizer
- Owner: ladeiko
- License: mit
- Created: 2018-07-10T11:54:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-02T10:25:21.000Z (about 6 years ago)
- Last Synced: 2024-11-18T04:51:58.096Z (about 2 months ago)
- Topics: data-synchronization, ios, swift
- Language: Swift
- Size: 28.3 KB
- Stars: 9
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - OneWaySynchronizer - The simplest abstraction to synchronize local data with remote source. (Data Structures / Algorithms / Getting Started)
- awesome-ios-star - OneWaySynchronizer - The simplest abstraction to synchronize local data with remote source. (Data Structures / Algorithms / Getting Started)
- fucking-awesome-ios - OneWaySynchronizer - The simplest abstraction to synchronize local data with remote source. (Data Structures / Algorithms / Getting Started)
- fucking-awesome-ios - OneWaySynchronizer - The simplest abstraction to synchronize local data with remote source. (Data Structures / Algorithms / Getting Started)
README
[![Build Status](https://travis-ci.org/ladeiko/OneWaySynchronizer.svg?branch=master)](https://travis-ci.org/ladeiko/OneWaySynchronizer)
# Purpose
The simplest abstraction to synchronize local data with remote source. For iOS, written in swift.
## Overview
Many applications uses remote servers as sources for some data rendered later to user. Synchronization process is used to fetch data from remote server and store them locally. This operation consists of some standard stages: fetch, compare, diff, download new, etc... This module was created to simplify synchronization process by implementing all logic inside with interaction via protocol with external 'so-called' processor. All you need, just implement all requied async methods. All items should be unique and must have string unique keys. Synchronizer does not define order of items, it is responsibility of programmer. Demo example, fills order from server response and then sort items according to it.
## Installation
### Cocoapods
```ruby
pod "OneWaySynchronizer"
```### Manually
Clone repository and add files from ```Source``` folder to project.
## Usage
For detailed example see [Demo](Demo) folder.
## OneWaySynchronizer
### Syncrhonization flow
```
sync()
↓
post OneWaySynchronizerDidChangeSyncStatusNotification
↓
[called at the beginning of synchronization process]
owsSyncBegin
↓
[return list of items from remote source, for example, from server]
owsFetchSourceList
↓ ↓
┌─< err ok
│ ↓
│ [return unique keys of locally existing items]
│ owsGetLocalKeys
│ ↓ ↓
├─< err ok
│ ↓
│ [remove local items, because their keys were not found in source list]
│ owsRemoveLocalItems
│ ↓ ↓
├─< err ok
│ ↓
│ [define if synchronizer should update already existing item]
│ owsShouldUpdateItem
│ ↓ ↓
├─< err ok
│ ↓
│ [here you can reorder, filter items for next download operations]
│ owsPrepareDownload
│ ↓ ↓
├─< err ok
│ ↓
│ [download preview of item if necessary]
│ owsDownloadItemPreview <───────────────────────────┐
│ ↓ ↓ │
├─< err ok >── concurrent loop for all previews ──┘
│ ↓
│ [download main content of item if necessary]
│ owsDownloadItem <─────────────────────────────────┐
│ ↓ ↓ │
├─< err ok >── concurrent loop for all previews ─┘
│ ↓
│ [called after synchronization process]
└> owsSyncEnd
↓
sync completions
↓
post OneWaySynchronizerDidChangeSyncStatusNotification```
### Methods
* ```func sync(completion: @escaping OwsSyncCompletion = { _ in })```
Starts synchronization process. If another process is in progress, then after its completion new synchronization will be initiated, both completion callbacks will be called at the end of the last synchronization.
* ```func cancel()```
Cancels currently running synchonization. If no any synchronization is running, then does nothing.
### Options
* ```concurrency``` - number of concurrent tasks while downloading. 0 - means auto. Default is 0.
* ```downloadPreview``` - if true, then synchonizer should call method for preview downloading. Default is false.
* ```downloadContent``` - if true, then synchonizer should call method for content downloading. Default is true.
* ```stopOnError``` - if true, then sync will stop as soon as possible after first error. Default is true.## Changes
See [CHANGELOG](CHANGELOG.md)
## License
MIT. See [LICENSE](LICENSE)
## Author
Siarhei Ladzeika