Let start from background of my problem.
I have a Person
class which is used to parse JSON
response
class Person: NSObject, Mappable {
var ID : String?
var firstName : String?
var lastName : String?
convenience required init?(map: Map) {
self.init()
}
func mapping(map: Map) {
patientsCount <- map["patientsCount"]
status <- map["status"]
message <- map["Message"]
patientSearchArray <- map["patientsList_JSON"]
}
}
While on the other I have another class names PersonMO
which is used to save record in CoreData
@objc(Event)
class PersonMO: NSManagedObject {
@NSManaged var ID : String?
@NSManaged var firstName : String?
@NSManaged var lastName : String?
}
Now comes to main point. The problem I am facing is that I have to create two different classes for one purpose. Just like When JSON
comes form Server Side
then I have to parse it into Person
class and then I want to save that Person
into Core Data
for that I have to convert Person
class object to PersonMO
class object. Which seems like a bad practice.
Is there any way to use just one Class Person
will be used to parse JSON
and at the same time I want to use that Person
class to store data in Core Data.