/Queryable

Realm Queryable Extension

Primary LanguageSwiftMIT LicenseMIT

Queryable

Realm Query Extension

Build Status codecov codebeat badge Readme Score

Requirements

  • iOS 8.0+ / macOS 10.9+ / tvOS / watchOS
  • Xcode 8.0+
  • Swift 3.0+

Contribute

  • If you want to add something feels free to add pull request
  • If you find bug or suggestion, please create issue
  • Thanks for all starts

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

Then go to your project directory and run:

$ pod init

in Podfile add:

use_frameworks!

target '<Target Name>' do
    pod 'Queryable'
end

Usage

CUD operations

// Simple class
class Foo: Object {
	dynamic var bar = ""
}

// Conform to protocol
extension Foo: Queryable {}

// Create simple object
let foo = Foo()
foo.bar = "something"

// Save objec
foo.add()

// Update object
foo.update(transaction: {
    foo.bar = "something other"
}, completion: nil)

// Remove object
foo.remove()

Fetching objects

// Fetch all objects
_ = Foo.arrayOfObjects

// Realm results
_ = Foo.resultsOfObjects

// Fetch filtred array
_ = Foo.filtredArray("bar == 'something'")

// Fetch filtred results
_ = Foo.filtredResults("bar == 'something'")

DBManager

Queryable has also DBManger which provides generic methods

// Fetching objects
public class func getObjects<T: Object>(of entity: T.Type, filter: String? = nil) -> [T]

// Add
public class func add(object: Object) -> Bool

//Update
public class func update(transaction: @escaping ()->()) -> Bool

//Remove
public class func remove(object: Object) -> Bool

Remove all from Realm

public class func removeAll() -> Bool