Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

iphone - warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame

What does mean? I get this error when trying to iterate through a file in Cocoa obj-c.

I can't find any information on the web.

Would appreciate some help. Thanks.

EDIT

I've been following this tutorial (link) to preload Core Data. I've tried creating a Cococa application and have also tried doing this from within my iPhone app. I think all my setup code for Core Data is fine. Whenever this method is called I get EXEC BAD ACCESS.

- (void)loadInitialData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    // name ZSTREET_1   ZSTREET_2   ZCITY   ZZIP    ZURL    ZTEL    latitude    longitude

    NSString *path = [[NSBundle mainBundle] pathForResource:@"placesdata" ofType:@"txt"];

    NSString *fileString = [NSString stringWithContentsOfFile:path]; // reads file into memory as an NSString
    NSArray *lines = [fileString componentsSeparatedByString:@"
"]; // each line, adjust character for line endings
    NSManagedObjectContext *context = [self managedObjectContext];
    for (NSString *line in lines)

    {   
        NSLog(line);

        NSString* string = [[NSString alloc] initWithUTF8String:line];
        NSArray *parts = [string componentsSeparatedByString:@""];
        // value mapping
        NSString *name = [parts objectAtIndex:0];
        NSString *street_1 = [parts objectAtIndex:1];
        NSString *street_2 = [parts objectAtIndex:2];
        NSString *city = [parts objectAtIndex:3];
        NSString *zip = [parts objectAtIndex:4];
        NSString *url = [parts objectAtIndex:5];

        NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
        [f setNumberStyle:NSNumberFormatterDecimalStyle];

        NSNumber *latitude = [f numberFromString:[parts objectAtIndex:6]];
        NSNumber *longitude = [f numberFromString:[parts objectAtIndex:7]];
        [f release];
        // splitting the parts to create the objects

        Place *place = (Place *)[NSEntityDescription insertNewObjectForEntityForName:@"Place" inManagedObjectContext:context];
        Address *address = (Address *)[NSEntityDescription insertNewObjectForEntityForName:@"Address" inManagedObjectContext:context];
        Location *location = (Location *)[NSEntityDescription insertNewObjectForEntityForName:@"Location" inManagedObjectContext:context];

        // set attributes
        [place setValue:name forKey:@"name"];
        [address setValue:street_1 forKey:@"street_1"];
        [address setValue:street_2 forKey:@"street_2"];
        [address setValue:city forKey:@"city"];
        [address setValue:zip forKey:"@zip"];
        [address setValue:url forKey:@"url"];
        [location setValue:latitude forKey:@"latitude"];
        [location setValue:longitude forKey:@"longitude"];

        // link the objects together
        [place setValue:address forKey:@"address"];
        [place setValue:location forKeyPath:@"address.location"];

        [string release];
    }
    NSLog(@"Done initial load");
    NSError *error; 
    if (![context save:&error]) {
        NSLog(@"Error saving: %@", error);
    }
    [context release];
    [pool drain];


}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For other people running into this problem with entirely different code, this is a bit of a red herring.

The warning is from the debugger itself. The debugger creates a struct containing info for each object in the system. After the EXC_BAD_ACCESS, it tried to create one of these but was unable to. Note that this is a warning and not an error so it may even be expected in situations like this.

In any event, the details surrounding this don't matter. You've got to find the source of your EXC_BAD_ACCESS. A common cause is trying to access an object after it has been released.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...