Latest 0.4.0
Homepage https://github.com/JunSuzukiJapan/RealmFlow
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Dependencies RealmSwift
Frameworks Foundation
Authors

RealmFlow makes Realm operation more easy.

  • Define Realm operation as RealmFlow.
  • Write operations following the previous operation, using method chain.
  • Run Realm operation with realm.run(flow:).

RealmFlow call realm.beginTransaction() automatically, if needed.
So you don’t need to think about transaction

example:

import RealmSwift
import RealmFlow

class Dog : Object {
    @objc dynamic var name: String = ""
}

class Cat : Object {
    @objc dynamic var name: String = ""
}

// ...

func do_operations() {
  // define data
  let pochi = Dog()
  pochi.name = "Poti"
  let tama = Cat()
  tama.name = "Tama"
  let hachi = Dog()
  hachi.name = "Hachi"
  let taro = Dog()
  taro.name = "Taro"
  let jiro = Dog()
  jiro.name = "Jiro"

  // write operations (not run yet)
  let flow = Realm.Flow
      .add(pochi)  // add pochi
      .add(tama)
      .add(hachi)
      .objects(Dog.self)  // query type Dog
      .subscribe { results in  // process query results
          print("first subscribe")
          for dog in results {
              print("dog.name: (dog.name)")
          }
      }
      .objects(Cat.self)  // query type Cat
      .add(taro) // add taro
      .subscribe { results in  // process query type Cat results
          print("second subscribe")
          for cat in results {
              print("cat.name: (cat.name)")
          }
      }
      .delete(pochi) // delete pochi
      .add(jiro)
      .objects(Dog.self)  // query type Dog again
      .subscribe { results in
          print("third subscribe")
          for dog in results {
              print("dog.name: (dog.name)")
          }
      }

  // run operations
  let realm = try! Realm()
  let _ = try? realm.run(flow: flow)
}

Install

Carthage

github "JunSuzukiJapan/RealmFlow"

CocoaPods

pod 'RealmFlow', '~> 0.3'

CRUD Example codes

Create

“`swift: Create New Object
let hachi = Dog()
hachi.name = "Hachi"

let flow = Realm.Flow.add(hachi)

let realm = try! Realm()
let _ = try? realm.run(flow: flow)

## Read

```swift: Query
    let flow = Realm.Flow.objects(Dog.self)
        .subscribe { results in
            let name = results.first?.name ?? "No dog"
            print("dog name: (name)")
        }

    let realm = try! Realm()
    let _ = try? realm.run(flow: flow)

Update

“`swift: Update
let flow = Realm.Flow.objects(Dog.self)
.subscribe_with_write_permission { (realm, results) in
results.first?.name = "Pochi"
}

let realm = try! Realm()
let _ = try? realm.run(flow: flow)

## Delete

```swift: Delete
    let flow = Realm.Flow.objects(Dog.self)
        .subscribe_with_write_permission { (realm, results) in
            if let dog = results.first {
                realm.delete(dog)
            }
        }

    let realm = try! Realm()
    let _ = try? realm.run(flow: flow)

Credits

RealmFlow was inspired by RealmIO.

Latest podspec

{
    "name": "RealmFlow",
    "version": "0.4.0",
    "summary": "RealmFlow makes Realm operation more easy.",
    "description": "RealmFlow makes Realm operation more easy.n  - Define Realm operation as `RealmFlow`.n  - Write operations following the previous operation, using method chain.n  - Run Realm operation with `realm.run(flow:)`.nnRealmFlow call ```realm.beginTransaction()``` automatically, if needed.nSo you don't need to think about transaction.nnexample:nn```swiftnimport RealmSwiftnimport RealmFlownnclass Dog : Object {n    @objc dynamic var name: String = ""n}nnclass Cat : Object {n    @objc dynamic var name: String = ""n}nn// ...nnfunc do_operations() {n  // define datan  let pochi = Dog()n  pochi.name = "Poti"n  let tama = Cat()n  tama.name = "Tama"n  let hachi = Dog()n  hachi.name = "Hachi"n  let taro = Dog()n  taro.name = "Taro"n  let jiro = Dog()n  jiro.name = "Jiro"nn  // write operations (not run yet)n  let flow = Realm.Flown      .add(pochi)  // add pochin      .add(tama)n      .add(hachi)n      .objects(Dog.self)  // query type Dogn      .subscribe { results in  // process query resultsn          print("first subscribe")n          for dog in results {n              print("dog.name: (dog.name)")n          }n      }n      .objects(Cat.self)  // query type Catn      .add(taro) // add taron      .subscribe { results in  // process query type Catn          print("second subscribe")n          for cat in results {n              print("cat.name: (cat.name)")n          }n      }n      .delete(pochi) // delete pochin      .add(jiro)n      .objects(Dog.self)  // query type Dog againn      .subscribe { results inn          print("third subscribe")n          for dog in results {n              print("dog.name: (dog.name)")n          }n      }nn  // run operationsn  let realm = try! Realm()n  let _ = try? realm.run(flow: flow)n}n```",
    "homepage": "https://github.com/JunSuzukiJapan/RealmFlow",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "JunSuzukiJapan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JunSuzukiJapan/RealmFlow.git",
        "tag": "0.4.0"
    },
    "swift_version": "4.1",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source_files": "RealmFlow/**/*",
    "frameworks": "Foundation",
    "dependencies": {
        "RealmSwift": [
            "~> 3.1"
        ]
    }
}

Pin It on Pinterest

Share This