Reputation: 999
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 :)
Upvotes: 1
Views: 1629
Reputation: 31362
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.
Upvotes: 2
Reputation: 96974
It would be difficult to encapsulate a complete solution to your answer, as your question is fairly broad without seeing your code.
Try to walk through Apple's excellent Books and Recipes sample applications, which cover the Core Data concepts you'll need to progress with your own project.
Upvotes: 3
Reputation: 10860
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.
Upvotes: 1