This is a followup question from the comments in the following How to map nested complex JSON objects and save them to core data?.
Imagine that I already have this code for my app.
class Passenger{
var name: String
var number: String
var image : UIImage
// init method
}
class Trip {
let tripNumber : Int
let passenger : Passenger
init(tripNumber: Int, passenger: Passenger) {
self.tripNumber = tripNumber
self.passenger = passenger
}
}
Now I've decided to add persistence for my app. I just want to have a table of Trips. I want to show the passengers under trips, but don't need a table to query passengers directly. It's just a custom object/property of trip. Every time I access passenger it would be through Trips.
So is there a way that I can create a new subclass of NSManagedObject named 'TripEntity' and store my passengers — WITHOUT 1. creating another NSManagedObject subclass for 'Passenger' 2. Creating a relationship with an inverse relationship between Passenger and Trip? Simply put I just want it to be an attribute. Conceptually to me it's also just an attribute. It's not really a relationship...
Or is that once you're using Core-data then every custom type needs to be explicitly a subclass of NSManagedObject? Otherwise it won't get persisted. I'm guessing this also what object graph means. That your graph needs to be complete. Anything outside the graph is ignored...
I'm asking this because the JSON object that I actually want to store is gigantic and I'm trying to reduce the work needed to be done.
Passenger
object be assigned to more than one trip? If so, you will need to work out some way of uniquing them because if they are encoded in an attribute, each Trip object will have distinct Passengers. 2) can each trip have more than one passenger? If not, you could just add each of the Passenger properties as an attribute of Trip, and avoid the encode hassle. 3) How big are the UIImages - they might be better stored in the file system and with a filepath stored in CoreData. – CrocoitePassenger
object can be assigned to multiple trips across a period of time. That being said I don't understand the problem you're mentioning. Can you elaborate? 2) Yes. It can be more than one. 3) Good point. – Febrifugal