Core data CoreData:删除所有元素后managedObjectContext上的怪异元素

Core data CoreData:删除所有元素后managedObjectContext上的怪异元素,core-data,managedobjectcontext,Core Data,Managedobjectcontext,我拿东西有困难。通过使用sql编辑器检查,我可以看到带有两个字段(integer position和string weburl)的表Web在抓取之前是空的。但是,在获取之后: NSArray * arrwebs = [managedObjectContext executeFetchRequest:allwebs error:&error]; 它有一个要素: "Error: (null) 2013-02-05 15:01:39

我拿东西有困难。通过使用sql编辑器检查,我可以看到带有两个字段(integer position和string weburl)的表Web在抓取之前是空的。但是,在获取之后:

NSArray * arrwebs = [managedObjectContext 
                             executeFetchRequest:allwebs error:&error];
它有一个要素:

"Error: (null)
2013-02-05 15:01:39.001 Assignment3-1[36607:c07] arrWwebs has 1 elements
2013-02-05 15:01:39.001 Assignment3-1[36607:c07] Postition: 0"
网络不应该是空的吗?在此之前,我已经删除了元素(通过编程和sql编辑器)

代码如下:

-(void) logElements
{
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];    
    NSManagedObjectContext *managedObjectContext = delegate.managedObjectContext;
    NSManagedObject  *newWebs;

    newWebs = [NSEntityDescription insertNewObjectForEntityForName:@"Webs" inManagedObjectContext:managedObjectContext];

    NSFetchRequest * allwebs = [[NSFetchRequest alloc] init];
    [allwebs setEntity:[NSEntityDescription entityForName:@"Webs" inManagedObjectContext:managedObjectContext]];
    [allwebs setIncludesPropertyValues:NO]; //only fetch the managedObjectID

    NSError *error = nil;
    NSArray * arrwebs = [managedObjectContext executeFetchRequest:allwebs error:&error];

    NSLog(@"Error: %@", [error localizedDescription]);
    NSLog(@"arrWwebs has %d elements", [arrwebs count]);

    for (NSManagedObject * info in arrwebs) {
        //[managedObjectContext deleteObject:webobject];
        NSLog(@"Postition: %@", [info valueForKey:@"position"]);
        NSLog(@"URL: %@", [info valueForKey:@"weburl"]);
    }

    if (![managedObjectContext save:&error]) {
        NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
    }    
}

有什么想法吗?

您正在插入一个
Webs
对象作为
newWebs
。因此,结果是预期的。

您正在将
Webs
对象作为
newWebs
插入。所以结果是意料之中的。

欢迎来到Stackoverflow,archipestre。在正确或有用的答案上打勾是一种习惯。请在启用后立即执行此操作。谢谢Mundi。就是这样。欢迎来到Stackoverflow,archipestre。在正确或有用的答案上打勾是一种习惯。请在启用后立即执行此操作。谢谢Mundi。就这样。