Created
March 13, 2017 14:16
-
-
Save alexanderkhitev/5700471d620ea9e77b62a93e326a0e11 to your computer and use it in GitHub Desktop.
Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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