Core data 更新CoreData中的单个记录

Core data 更新CoreData中的单个记录,core-data,ios6,Core Data,Ios6,我有以下情况: 数据从CoreData实体读取到名为observationList的数组中 通过阵列循环检查数据,可能需要更新位置x处的数据 for (int x = 0; x < [observationList count]; x++) { //check for need of data update - if there is a need to update .... for (NSManagedObject *schoolObject in [self observa

我有以下情况:

数据从
CoreData
实体读取到名为observationList的数组中

通过阵列循环检查数据,可能需要更新位置x处的数据

for (int x = 0; x < [observationList count]; x++)
{
  //check for need of data update - if there is a need to update ....

  for (NSManagedObject *schoolObject in [self observationList])
  {
  [schoolObject setValue:[NSString stringWithFormat:@"%@", classCheck] forKey:@"obsClassName"];
  }

  NSError *error;
  [context save:&error];
}
for(int x=0;x<[observationList count];x++)
{
//检查是否需要数据更新-如果需要更新。。。。
对于(NSManagedObject*schoolObject在[self observationList]中)
{
[schoolObject setValue:[NSString stringWithFormat:@“%@”,classCheck]forKey:@“obsClassName”];
}
n错误*错误;
[上下文保存:&错误];
}
我意识到我所做的是更新CoreData中的所有记录,因此我要问的是如何具体更新位置x处的记录。

这是否可行? 检查后,按如下方式获取对象:

NSManagedObject *schoolObject = [[self observationList] objectAtIndex:x]
然后根据需要设置该值。

这样行吗? 检查后,按如下方式获取对象:

NSManagedObject *schoolObject = [[self observationList] objectAtIndex:x]

然后根据需要设置值。

如果
schoolObject
位于
observationList
中,则只需更新位置x处的特定记录即可

for (int x = 0; x < [observationList count]; x++)
{
  NSManagedObject *schoolObject = [[self observationList] objectAtIndex:x];

   //check for need of data update - if there is condition

  [schoolObject setValue:[NSString stringWithFormat:@"%@", classCheck] forKey:@"obsClassName"];

  NSError *error;
  [context save:&error];
}
for(int x=0;x<[observationList count];x++)
{
NSManagedObject*schoolObject=[[自我观察列表]对象索引:x];
//检查是否需要数据更新-如果有条件
[schoolObject setValue:[NSString stringWithFormat:@“%@”,classCheck]forKey:@“obsClassName”];
n错误*错误;
[上下文保存:&错误];
}

首先从具有特定位置的
观察列表
中提取
学校对象
,并使用适当的条件进行更新

如果
学校对象
位于
观察列表
中,则只需更新位于x位置的特定记录

for (int x = 0; x < [observationList count]; x++)
{
  NSManagedObject *schoolObject = [[self observationList] objectAtIndex:x];

   //check for need of data update - if there is condition

  [schoolObject setValue:[NSString stringWithFormat:@"%@", classCheck] forKey:@"obsClassName"];

  NSError *error;
  [context save:&error];
}
for(int x=0;x<[observationList count];x++)
{
NSManagedObject*schoolObject=[[自我观察列表]对象索引:x];
//检查是否需要数据更新-如果有条件
[schoolObject setValue:[NSString stringWithFormat:@“%@”,classCheck]forKey:@“obsClassName”];
n错误*错误;
[上下文保存:&错误];
}

首先从
observationList
获取
schoolObject
的具体位置,并用适当的条件进行更新

您的循环没有增加任何内容,这是一个输入错误吗?您不会保存每个对象,只保存那些有更改的对象。是的,输入错误-谢谢-现在更正。@Abizern我不确定是否同意-for(NSManagedObject*在[自我观察列表]中的学校对象)“行”表示我浏览了所有列表,但我想做的只是将记录定位在位置x。您的循环没有增加任何内容,这是一个输入错误吗?您不会保存每个对象,只保存那些有更改的对象。是的,输入错误-谢谢-现在更正。@Abizern我不确定是否同意-中的for(NSManagedObject*schoolObject)[self observationList])行表示我浏览了所有列表,但我想做的只是将记录定位在位置x。谢谢,但它似乎没有。谢谢,但它似乎没有。