2010-09-29 244 views
-1

我正在嘗試將數組保存到核心數據。我一直在評論以下主題: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」的任何值。

問候, 斯蒂芬

回答

2

你似乎是混亂的三件事情的核心數據,SQLite和用戶默認值。您所包含的代碼中沒有任何與Core Data相關的內容。

也許你應該退後一步,閱讀NSUser默認的文檔。

+0

感謝Nick,我放棄了這種方法,只是將數組作爲字符串存儲在Core Data中。 – Stephen 2010-09-30 15:43:54