0
我有这个应用程序使用核心数据和一个NSArrayController来管理表中的一些对象。我有下面的代码来获取目录上的一些对象。我的问题是关于下面标有“处理文件”的部分。我使用url创建一个新的Video对象,我使用我写的自定义函数复制元数据属性。该对象现在被插入到managedObjectContext中。我的问题是,因为我有我的NSArrayController绑定到我的managedObjectContext,为什么我还必须[self addObject:newVideo]让我的表上显示对象?有没有办法强制数组控制器从managedObjectContext中提取对象而无需手动添加它?每次添加或删除对象时,都必须更新这两项操作。使用NSArrayController添加managedObjectContext对象
for (NSURL *url in _dirEnumerator) {
NSNumber *_isDirectory = nil;
[url getResourceValue:&_isDirectory forKey:NSURLIsDirectoryKey error:NULL];
if (![_isDirectory boolValue]) {
if (([_mediaTypes containsObject:[[url pathExtension]uppercaseString]])) {
// Handle the files
Video *newVideo = [NSEntityDescription insertNewObjectForEntityForName:@"Video" inManagedObjectContext:_managedObjectContext];
[newVideo copyAttributesFrom:url];
[self addObject:newVideo];
NSLog(@"Inserting video: %@",[newVideo valueForKey:@"name"]);
}
}
}