English 中文(简体)
穿过NSManagedObjectContext物体?
原标题:Iterate through NSManagedObjectContext objects?

I want to iterate through all of the objects in my NSManagedObjectContext, and update them manually. Then, every managed object should be updated. What s the best way to do this?

问题回答

理论上,你可以通过你所管理的物体模型中的所有实体说明,为它们提出不准确的要求,然后处理所有返还物体,并作一些更新。 例:

// Given some NSManagedObjectContext *context
NSManagedObjectModel *model = [[context persistentStoreCoordinator]
                               managedObjectModel];
for(NSEntityDescription *entity in [model entities]) {
    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
    [request setEntity:entity];
    NSError *error;
    NSArray *results = [context executeFetchRequest:request error:&error];
    // Error-checking here...
    for(NSManagedObject *object in results) {
        // Do your updates here
    }
}

请注意,您可以在必要时通过下列两种方式重新列出国家抽样调查目标:对等级平等进行测试(使用< 编码>isKindOfClass:或相关方法),或将现有实体的类别(使用管理的ObjectClassName上的财产(entity)与方法)合并。

这似乎像对这个问题采取非常严厉的做法。 如果数据装上坏数据,则istrongly建议,在你进口数据时加以固定。 时间回答会有助于你做些什么,但我强烈怀疑你会遇到这种错误。 通过整个数据库收集潜在坏数据的工作效率很低。

如果用错误数据制造有管理的物体,我将检查,以确保你在模型中为所有实体的所有财产确定违约值。 这样,你就可以确定,只要你在你的背景中插入一个目标,就会包含这些价值观。 从那以后,你就可以将财产确定给你们所需要的一切。





相关问题
Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签