将数组保存到核心数据
问题描述:
我正在尝试将数组保存到核心数据。我一直在评论以下主题:Storing custom objects in an NSMutableArray in NSUserDefaults(特别是Stefan的回答)。我的代码如下:将数组保存到核心数据
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];
}
上面的代码工作,但是当我看着我的表(通过在浏览器SQLITE经理),我没有看到钥匙“temp_start_time”的任何值。
问候, 斯蒂芬
答
你似乎是混乱的三件事情的核心数据,SQLite和用户默认值。您所包含的代码中没有任何与Core Data相关的内容。
也许你应该退后一步,阅读NSUser默认的文档。
感谢Nick,我放弃了这种方法,只是将数组作为字符串存储在Core Data中。 – Stephen 2010-09-30 15:43:54