Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderkhitev/5700471d620ea9e77b62a93e326a0e11 to your computer and use it in GitHub Desktop.
Save alexanderkhitev/5700471d620ea9e77b62a93e326a0e11 to your computer and use it in GitHub Desktop.
Example
import Foundation
import RealmSwift
import ObjectMapper
class RealmUser: Object, Mappable {
dynamic var id = "" // id
dynamic var phoneNumber = ""
dynamic var isMain = false
dynamic var userInfo: RealmUserInfo? = nil
// MARK: - Local data
/// It is used to find a user number among the contacts that are used on the device. And set the indicator.
dynamic var localPhoneNumberID: String?
override class func primaryKey() -> String? {
return "id"
}
convenience required init?(map: Map) {
self.init()
}
func mapping(map: Map) {
if map.mappingType == .fromJSON {
id <- map["id"]
phoneNumber <- map["phoneNumber"]
isMain <- map["isMain"]
userInfo <- map["userInfo"]
} else {
id >>> map["id"]
phoneNumber >>> map["phoneNumber"]
isMain >>> map["isMain"]
userInfo >>> map["userInfo"]
}
}
}
// RealmUserInfo.swift
// SwiftChats
//
// Created by Alexsander Khitev on 2/6/17.
// Copyright © 2017 Alexsander Khitev. All rights reserved.
//
import Foundation
import RealmSwift
import ObjectMapper
class RealmUserInfo: Object, Mappable {
dynamic var id = ""
dynamic var firstName = ""
dynamic var lastName = ""
dynamic var photoPath: String?
override class func primaryKey() -> String? {
return "id"
}
convenience required init?(map: Map) {
self.init()
}
func mapping(map: Map) {
if map.mappingType == .fromJSON {
id <- map["id"]
firstName <- map["firstName"]
lastName <- map["lastName"]
photoPath <- map["photoPath"]
} else {
id >>> map["id"]
firstName >>> map["firstName"]
lastName >>> map["lastName"]
photoPath >>> map["photoPath"]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment