All Projects → blkbrds → realm-mapper-ios

blkbrds / realm-mapper-ios

Licence: MIT license
Realm + ObjectMapper

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to realm-mapper-ios

realms-ios
Safe method for Realm
Stars: ✭ 22 (-21.43%)
Mutual labels:  realm, objectmapper, realmswift
DailyFeed
iOS client for newsapi.org
Stars: ✭ 128 (+357.14%)
Mutual labels:  realm, realmswift
Realm-and-Swift-Codable
How to implement Swift 4 Codable with Realm Database
Stars: ✭ 34 (+21.43%)
Mutual labels:  realm, realmswift
RealmSwiftService
Support Realm CRUD functions. Support Dao Object and Protocol Extension.
Stars: ✭ 12 (-57.14%)
Mutual labels:  realm, 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 (-46.43%)
Mutual labels:  objectmapper, realmswift
Swift-Viper-Weather-App
iOS app with Clean Architecture
Stars: ✭ 20 (-28.57%)
Mutual labels:  realm, realmswift
solar-weather
React Native Weather App w. Realm, Redux, ReasonReact & Forecast.io
Stars: ✭ 13 (-53.57%)
Mutual labels:  realm
cordova-plugin-realm
Unofficial Cordova plugin for Realm Mobile Database.
Stars: ✭ 29 (+3.57%)
Mutual labels:  realm
wikilight
A lightweight Wikipedia Client
Stars: ✭ 50 (+78.57%)
Mutual labels:  realm
awesome-demo-app
100% programmatically written in Swift. Clearly demonstrating the RxSwift, RxCocoa, RxRealm & SnapKit.
Stars: ✭ 16 (-42.86%)
Mutual labels:  realmswift
keycloak-home-idp-discovery
Keycloak: Home IdP Discovery - discover home identity provider or realm by email domain
Stars: ✭ 42 (+50%)
Mutual labels:  realm
electron-react-ts-rxdb-realm-sqlite
Demo of Native Databases with Electron and ReactJS. Realm, SQLite and RxDB ( with LevelDB/IndexedDB/InMemory adapters)
Stars: ✭ 27 (-3.57%)
Mutual labels:  realm
ExamplesAndroid
Simple Example of Android [APIFacebook,APIGoogleMaps,APITwitter,Volley,Picasso etc etc etc]
Stars: ✭ 24 (-14.29%)
Mutual labels:  realm
myplanet
🌕 myPlanet android app reads data from 🌎 for offline use as well as it collect usage data and sends them back to the Planet.
Stars: ✭ 17 (-39.29%)
Mutual labels:  realm
RealmTaskTracker
SwiftUI version of the MongoDB Realm iOS tutorial
Stars: ✭ 24 (-14.29%)
Mutual labels:  realmswift
android-kotlin-sample-note
Android Kotlin Sample Note - Dagger2, Realm CRUD, RxJava2
Stars: ✭ 29 (+3.57%)
Mutual labels:  realm
realm-tester
Writing tests using Realm Java
Stars: ✭ 14 (-50%)
Mutual labels:  realm
SilverScreener
A feature-rich movie guide app, that lets you discover movies from TMDb.
Stars: ✭ 24 (-14.29%)
Mutual labels:  realm
Android-ORM-Benchmarks
No description or website provided.
Stars: ✭ 25 (-10.71%)
Mutual labels:  realm
react-native-base-project
Base react native application for scalable project using Redux + React Navigation + Code Push + Realm + Axios + i18n + Google Analytics + Facebook login with fbsdk...
Stars: ✭ 31 (+10.71%)
Mutual labels:  realm

Build Status CocoaPods Compatible Platform Code Coverage

RealmSwift ObjectMapper

Realm + ObjectMapper

Requirements

  • iOS 8.0+
  • Xcode 8.3 (Swift 3.1)

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 RealmMapper 3.0+.

To integrate RealmMapper 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 'RealmMapper', '~> 3.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 RealmMapper

final class User: Object, StaticMappable {
    dynamic var id: String!
    dynamic var name: String?
    dynamic var address: Address?
    let dogs = List<Dog>()
    
    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? {
        do {
            let realm = try Realm()
            return realm.object(ofType: self, forMapping: map)
        } catch {
            return nil
        }
    }
}

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

    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

do {
  let realm = try Realm()
  try realm.write {
    realm.map(User.self, json: jsUser) // map JSON object
    realm.map(Shop.self, json: jsShops) // map JSON array
  }
} catch {
}

nil value will be bypass, if you want set nil please use NSNull() instead

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].