All Projects → blkbrds → realms-ios

blkbrds / realms-ios

Licence: MIT license
Safe method for Realm

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
shell
77523 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to realms-ios

realm-mapper-ios
Realm + ObjectMapper
Stars: ✭ 28 (+27.27%)
Mutual labels:  realm, objectmapper, realmswift
Perfect-Server-Side-Swift iOS-App
A family tree API server implementation with iOS client. Server has been implemented with Perfect: Server-Side Swift And iOS client is in pure Swift.
Stars: ✭ 15 (-31.82%)
Mutual labels:  objectmapper, realmswift
Realm-and-Swift-Codable
How to implement Swift 4 Codable with Realm Database
Stars: ✭ 34 (+54.55%)
Mutual labels:  realm, realmswift
RealmSwiftService
Support Realm CRUD functions. Support Dao Object and Protocol Extension.
Stars: ✭ 12 (-45.45%)
Mutual labels:  realm, realmswift
DailyFeed
iOS client for newsapi.org
Stars: ✭ 128 (+481.82%)
Mutual labels:  realm, realmswift
Swift-Viper-Weather-App
iOS app with Clean Architecture
Stars: ✭ 20 (-9.09%)
Mutual labels:  realm, realmswift
Todo Android
[Google Play] Todo Android App using Realm, Material Design, and Dagger 2.
Stars: ✭ 107 (+386.36%)
Mutual labels:  realm
Realmfieldnameshelper
Realm extension library used to create more type-safe queries.
Stars: ✭ 174 (+690.91%)
Mutual labels:  realm
Apiclient
A easy to use api client that combines the power of Retrofit, Realm, Gson, Rxjava and Retrolambda in a easy to use library for Java and Android
Stars: ✭ 100 (+354.55%)
Mutual labels:  realm
Todolist
A simple ToDoList written in Swift
Stars: ✭ 100 (+354.55%)
Mutual labels:  realm
Eblo
A Fancy Engineering Blogs Reader
Stars: ✭ 57 (+159.09%)
Mutual labels:  realm
Aaf Easydiary
📘 A diary application optimized for user experience.
Stars: ✭ 216 (+881.82%)
Mutual labels:  realm
Realm Draw
The official Realm Draw app used in promotional videos
Stars: ✭ 150 (+581.82%)
Mutual labels:  realm
Autograph
A GraphQL Client in Swift
Stars: ✭ 117 (+431.82%)
Mutual labels:  realm
Newgank
Cool Android client for gankio (Java).
Stars: ✭ 179 (+713.64%)
Mutual labels:  realm
Swift Zhi
iOS ZhiHuDaily client, implemented in Swift
Stars: ✭ 103 (+368.18%)
Mutual labels:  realm
Realmcontent
Light Realm-powered content management system
Stars: ✭ 237 (+977.27%)
Mutual labels:  realm
Realm Browser
Android Database Browser for realm-java
Stars: ✭ 101 (+359.09%)
Mutual labels:  realm
Nearbyweather
NearbyWeather is an open source weather app for iOS, which uses the OpenWeatherMap API. With this project developers are invited to learn advanced iOS concepts, as well as to contribute further advancements. Fork this repo to get started.
Stars: ✭ 146 (+563.64%)
Mutual labels:  realm
Now
Jsoup + MaterialViewPager + RxJava2 + Retrofit + Lifecycle + Realm + Fresco + Retrolambda example 一款Android图文精选app,通过抓取网页获得图文列表。目前包含猫弄(MONO)早午茶、站酷(Zcool)精选、国家地理(National Geographic)每日一图、知乎日报、豆瓣一刻(Moment)。
Stars: ✭ 189 (+759.09%)
Mutual labels:  realm

Build Status CocoaPods Compatible Platform Coverage Status

RealmSwift ObjectMapper

Realm + ObjectMapper

Requirements

  • iOS 8.0+
  • Xcode 9.2 (Swift 4.0+)

Installation

Embedded frameworks require a minimum deployment target of iOS 8

CocoaPods

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

$ gem install cocoapods

CocoaPods 1.2+ is required to build RealmS 2.3+

To integrate RealmS into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'RealmS', '~> 4.0.0'

Then, run the following command:

$ pod install

Usage

Mapping

Rule:

  • Object has primaryKey must be StaticMappable (i)
  • Object has no primaryKey should be Mappable (ii)
import RealmSwift
import ObjectMapper
import RealmS

// (i)
final class User: Object, StaticMappable {
    @objc dynamic var id: String!
    @objc dynamic var name: String?
    @objc dynamic var address: Address?
    let dogs = List<Pet>()

    override class func primaryKey() -> String? {
        return "id"
    }

    func mapping(map: Map) {
        name <- map["name"]
        address <- map["address"]
        dogs <- map["dogs"]
    }

    static func objectForMapping(map: Map) -> BaseMappable? {
        return RealmS().object(ofType: self, forMapping: map)
    }
}

// (ii)
final class Address: Object, Mappable {
    @objc dynamic var street = ""
    @objc dynamic var city = ""
    @objc dynamic var country = ""

    @objc dynamic var phone: Phone?

    let users = LinkingObjects(fromType: User.self, property: "address")

    convenience required init?(map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        street <- map["street"]
        city <- map["city"]
        country <- map["country"]
        phone <- map["phone"]
    }
}

Import JSON to Realm

let realm = RealmS()
realm.write {
  realm.map(User.self, jsUser) // map JSON object
  realm.map(Shop.self, jsShops) // map JSON array
}
  • nil value will be bypass, if you want set nil please use NSNull() instead.

Clean Up

extension User {
    override public class func relativedTypes() -> [Object.Type] {
        return [Address.self, Pet.self]
    }

    override public class func clean() { }
}

extension Address {
    override class func relativedTypes() -> [Object.Type] {
        return [Phone.self]
    }

    override class func clean() {
        let realm = RealmS()
        let objs = realm.objects(self).filter("users.@count = 0")
        realm.write {
            realm.delete(objs)
        }
    }
}

Address table will be clean-up after a User is deleted from Realm.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].