1

I am having trouble with the fetching. Checking with the sql editor I can see that the table webs with two fields (integer position AND string weburl) is empty just before the fetching. However, after the fetching:

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

it has one element:

"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"

Shouldn't arrwebs be empty? I have deleted before this the elements (via programatically and via sql editor);

The code is as follows:

-(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]);
    }    
}

Any idea?

Mundi
  • 79,884
  • 17
  • 117
  • 140
archipestre
  • 182
  • 9

1 Answers1

1

You are inserting a Webs object as newWebs. So the result is expected.

Mundi
  • 79,884
  • 17
  • 117
  • 140