Latest 0.1.0
Homepage https://github.com/soutaro/Majima
License MIT
Platforms ios 8.0, requires ARC
Authors

Three-way merge for array and dictionary, in Swift.

public enum Result<T> {
  case Merged(T)
  case Conflicted
}

public class ThreeWayMerge {
  public static func merge<T: Equatable>(base base: [T], mine: [T], theirs: [T]) -> Result<[T]>
  public static func merge<K, V: Equatable>(base base: [K: V], mine: [K: V], theirs: [K: V]) -> Result<[K: V]>
}

Array

import Majima

let base = [1, 2, 3]
let mine = [0, 1, 2, 3]   // 0 is inserted
let theirs = [1, 2]       // 3 is deleted

let result = ThreeWayMerge.merge(base: base, mine: mine, theirs: theirs)
// .Merged([0, 1, 2])     // 0 is inserted, 3 is deleted

The diff calculation is naively implemented. You may find issues when you run on big array.

Dictionary

import Majima

let base = ["name": "Soutaro", "email": "[email protected]"]
let mine = ["name": "Soutaro", "email": "[email protected]"] // email is updated
let theirs = ["name": "Soutaro Matsumoto", "email": "[email protected]"] // name is updated

let result = ThreeWayMerge.merge(base: base, mine: mine, theirs: theirs)
// .Merged(["name": "Soutaro Matsumoto", "email": "[email protected]"])

Installation

You can install the library via Cocoapods.

pod 'Majima'

Copyright

Soutaro Matsumoto.
See LICENSE for detail.

Latest podspec

{
    "name": "Majima",
    "version": "0.1.0",
    "license": {
        "type": "MIT"
    },
    "homepage": "https://github.com/soutaro/Majima",
    "authors": {
        "Soutaro Matsumoto": "[email protected]"
    },
    "summary": "Three-way merge for array and dictionary, in Swift",
    "source": {
        "git": "https://github.com/soutaro/Majima.git",
        "tag": "0.1.0"
    },
    "source_files": "Majima/*.swift",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This