The simplest abstraction to synchronize local data with remote source. For iOS, wirtten in swift.

Overview

Build Status

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

pod "OneWaySynchronizer"

Manually

Clone repository and add files from Source folder to project.

Usage

For detailed example see 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

License

MIT. See LICENSE

Author

Siarhei Ladzeika [email protected]

You might also like...
Simple diff library in pure Swift

Diff Simple diffing library in pure Swift. Installing You can use Carthage or Swift Package Manager to install Diff. Usage Start by importing the pack

A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript

Dollar Dollar is a Swift library that provides useful functional programming helper methods without extending any built in objects. It is similar to L

Swift type modelling the success/failure of arbitrary operations.

Result This is a Swift µframework providing ResultValue, Error. ResultValue, Error values are either successful (wrapping Value) or failed (wrappi

Swift μ-framework for efficient array diffs and datasource adapters.
Swift μ-framework for efficient array diffs and datasource adapters.

Buffer Swift μ-framework for efficient array diffs, collection observation and data source implementation. C++11 port here Installation cd {PROJECT_RO

A Generic Priority Queue in Pure Swift

SwiftPriorityQueue SwiftPriorityQueue is a pure Swift (no Cocoa) implementation of a generic priority queue data structure, appropriate for use on all

Super lightweight DB written in Swift.
Super lightweight DB written in Swift.

Use of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. Pencil makes us

A fast Swift diffing library.

HeckelDiff Pure Swift implementation of Paul Heckel's A Technique for Isolating Differences Between Files Features This is a simple diff algorithm tha

NSCoding's counterpart for Swift structs.
NSCoding's counterpart for Swift structs.

Dekoter Why You Might Be Interested How Much Familiar It Feels One More Example What We've Learned from It Features Save an Object to UserDefaults Arc

A Distributed Value Store in Swift.
A Distributed Value Store in Swift.

Impeller is a Distributed Value Store (DVS) written in Swift. It was inspired by successful Distributed Version Control Systems (DVCSes) like Git and

Owner
Siarhei Ladzeika
Siarhei Ladzeika
Examples of commonly used data structures and algorithms in Swift.

Swift Structures This project provides a framework for commonly used data structures and algorithms written in a new iOS development language called S

Wayne Bishop 2.1k Dec 28, 2022
A Graph Data Structure in Pure Swift

SwiftGraph SwiftGraph is a pure Swift (no Cocoa) implementation of a graph data structure, appropriate for use on all platforms Swift supports (iOS, m

David Kopec 700 Dec 16, 2022
Algorithms and data structures in Swift, with explanations!

Welcome to the Swift Algorithm Club! Here you'll find implementations of popular algorithms and data structures in everyone's favorite new language Sw

raywenderlich 27.3k Jan 8, 2023
Simple implementations of various dynamic data structures in Swift.

SwiftDataStructures Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installatio

Hector Delgado 0 Oct 21, 2021
Arena is an implementation of the generational arena data structure in Swift.

Arena This package is very much work in progress. Arena is an implementation of the generational arena data structure in Swift. An Arena is useful for

null 7 Dec 7, 2021
EKAlgorithms contains some well known CS algorithms & data structures.

EKAlgorithms EKAlgorithms is a set of computer exercises implemented in Objective-C. Data structures, well known algorithms, CS curiosities, you name

Evgeny Karkan 2.4k Jan 4, 2023
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
Swift-extensions - Swift package extending the Swift programming language.

swift-extensions A package containing extensions for the Swift programming language. Contribution Reporting a bug If you find a bug, please open a bug

Alexandre H. Saad 2 Jun 12, 2022
LotsOfCats - An iOS app that lets you swipe through random cat pictures

LotsOfCats This is an iOS app that lets you swipe through random cat pictures! I

null 1 Jan 9, 2022
Fast sorted collections for Swift using in-memory B-trees

Fast Sorted Collections for Swift Using In-Memory B-Trees Overview Reference Documentation Optimizing Collections: The Book What Are B-Trees? Why In-M

null 1.3k Dec 20, 2022