什么意思?尝试遍历 Cocoa obj-c 中的文件时出现此错误。
我在网上找不到任何信息。
希望得到一些帮助。谢谢。
编辑
我一直在学习本教程 (link)预加载核心数据。我试过创建一个 Cococa 应用程序,也试过在我的 iPhone 应用程序中执行此操作。我认为我所有的核心数据设置代码都很好。每当调用此方法时,我都会收到 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:@"\r"]; // 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:@"\t"];
// 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];
}
最佳答案
对于使用完全不同的代码遇到此问题的其他人来说,这有点转移注意力。
警告来自调试器本身。调试器创建一个结构,其中包含系统中每个对象的信息。在 EXC_BAD_ACCESS 之后,它试图创建其中之一但无法创建。请注意,这是警告而不是错误,因此在这种情况下甚至可能会出现这种情况。
无论如何,与此相关的细节并不重要。您必须找到 EXC_BAD_ACCESS 的来源。一个常见的原因是试图在一个对象被释放后访问它。
关于iphone - 警告 : Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3637714/