Been having a bit of a headache with this one and was wondering if someone could offer some advice!
Im implementing persistent storage with Core Data.
I have two Entities Car and Driver. A car can have many drivers.
In one view i am collecting the drivers and storing them to a NSMutableArray
This array is getting passed to another view and at some point i will be saving it against a Car
What i would like to do is save each driver from the array in a seperate row in the table of drivers (Just their name (NSString) which will be assigned to a Car.
Any suggestions or pointers in the right direction would be greatly appreciated!
Cheers :)
You mention that you have both Car and Driver entities, yet it sounds like you're trying to save your driver names directly as attributes of a car. Why are you just saving their NSString *name
to the car?
Instead of doing that, you should simply update the relationships between your car and its drivers. If you implement your entities as custom classes (and I highly recommend it - see this ADC guide ), then when you want to update who drives what car, you can simply say: [car addDriversObject:driver]
or [car removeDriversObject:driver]
.
Like Alex said, you may want to ensure you have a firm grasp on Core Data before heading out on your own too far.
i'm not a pro in using core data, but you can try to get data from your array using NSKeyArchiver and save returned NSData object to your database. it works fine with sqllite databases.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.