Iphone core data CountByEnumerating with State:对象:计数:错误

Iphone core data CountByEnumerating with State:对象:计数:错误,iphone,objective-c,ios,core-data,Iphone,Objective C,Ios,Core Data,我在向核心数据添加新关系时出现此错误。我在互联网上读到了很多资源,但它们帮不了我。。。也许你可以。。。 这是我的代码,然后我添加关系: std = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:self.context]; std.fio = fio.text; std.phone = phone.text; NSError *error; self.selectedG

我在向核心数据添加新关系时出现此错误。我在互联网上读到了很多资源,但它们帮不了我。。。也许你可以。。。 这是我的代码,然后我添加关系:

std = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:self.context];
std.fio = fio.text;
std.phone = phone.text;
NSError *error;
self.selectedGroups = MSGTVC.selectedGroups;
for(Group *info in self.selectedGroups){
    [std addGroupsObject:info];
}    if (![self.context save:&error]) {
    NSLog(@"Cant Save: %@", [error localizedDescription]);    }
行内[std addGroupsObject:info];是错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Group CountByEnumerating with State:objects:count:]:发送到实例0x816a1c0的无法识别的选择器”

这是我的代码,然后我将值分配给SelectedGroup:

   NSArray *indexselected = [[NSArray alloc] initWithArray:[self.tableView indexPathsForSelectedRows
__OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0)]]; 

    for (NSIndexPath *into in indexselected)
        {

            self.selectedGroups = [self.group objectAtIndex:into.row];

           }

如果您能帮助解决此问题,我会很高兴的,提前谢谢。

您正在调用非数组的for循环(NSFastEnumeration)。自我是什么类型的。selectedGroups@property(非原子,保留)NSArray*选定组;我发现了这个问题,有必要使用NSMutableArray而不是NSArray,而且不要忘记初始化它:)