Tom G
Tom G

Reputation: 999

Saving to Core Data with NSMutableArray

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.

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

Answers (3)

mbauman
mbauman

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

Alex Reynolds
Alex Reynolds

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

Morion
Morion

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

Related Questions