2

i Have a BaseRequestObject of type NSObject,Mappable which is inherit by a object called User. I need to save this User object inside realmDB.

class BaseRequestBody: NSObject,Mappable {
override init() {

}

required init?(map: Map) {

}

func mapping(map: Map) {

}

}

UserObject which inhertits BaseRequestBody:-

class User: BaseRequestBody {
var id : String?
var name : String?    

override init() {
    super.init()
}

required init?(map: Map) {
    super.init(map: map)
}

override func mapping(map: Map) {
id     <- map["id"]
name   <- map["name"]
}
}

How to use this User object to store both in realmDatabase and use as a normal object.I am using this same object to parse alamofire data to userObject.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Abhijit Hadkar
  • 210
  • 2
  • 11

1 Answers1

0

There's no need to make BaseRequestBody inherit from NSObject, Object inherits from RLMObjectBase, which inherits from NSObject, so simply making BaseRequestBody a subclass of Object will also make it a subclass of NSObject.

class BaseRequestBody: Object,Mappable {
...
}

Unrelated to your issue, but there's no need to use ObjectMapper for decoding your object from JSON, you can simply use the Decodable protocol.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116