views:

50

answers:

1

Hello,

I'm trying to save an array to Core Data. I've been reviewing the following thread: http://stackoverflow.com/questions/537044/storing-custom-objects-in-an-nsmutablearray-in-nsuserdefaults (in particular the answer from Stefan). My code is as follows:

for (TempWorkout *newTempWorkout in items) 
        {
            NSString *strCounterInt = [NSString stringWithFormat:@"%d", counterInt];
            newTempWorkout.temp_time = strCounterInt; 
            newTempWorkout.temp_route = route.text;
            newTempWorkout.temp_activity = activity.text;
            newTempWorkout.temp_intensity = intensity.text;
            NSString *strTotalDistance = [NSString stringWithFormat:@"%.3f", totalDistance];
            newTempWorkout.temp_distance = strTotalDistance;
            newTempWorkout.temp_mapID = mapID;

            [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:startTimeArray] forKey:@"temp_start_time"];

            [self.tempWorkoutArray addObject:newTempWorkout];   
        }

The above code works, but when I look at my table (via SQLITE Manager in the browser), I don't see any values for key 'temp_start_time'.

Regards, Stephen

A: 

You appear to be confusing 3 things Core Data, SQLite and User Defaults. There is nothing related to Core Data in the code you included.

Perhaps you should step back and read the docs for NSUser defaults.

Nick
Thanks Nick, I've scrapped that approach and just stored the array as a string in Core Data.
Stephen