警告:正在尝试使用不在框架中的块创建USE_BLOCK_IN_FRAME变量 [英] warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame
问题描述
是什么意思?我得到这个错误时,试图遍历Cocoa obj-c中的文件。
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.
我一直在追踪本教学课程(链接)预加载Core Data。我试过创建一个Cococa应用程序,也试图这样做从我的iPhone应用程序。我认为我的所有设置代码Core Data是好的。每当这个方法被调用我得到EXEC BAD ACCESS。
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:@"\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];
}
推荐答案
这行是错误的,应该产生一个编译器警告:
This line is wrong and should produce a compiler warning:
NSString* string = [[NSString alloc] initWithUTF8String:line];
方法 initWithUTF8String:
8编码的C字符串,而不是 NSString
对象。
The method initWithUTF8String:
expects an UTF-8 encoded C string and not a NSString
object.
在继续之前,您应该修复所有编译器警告!并且你还应该检查 parts
数组实际上是否包含你想要的对象数量。您还需要使用NSLog的格式字符串,如果您的行包含任何%
字符,您甚至可能会崩溃。
Before you continue you should fix all compiler warnings! And you also should check that the parts
array actually contains as many objects as you expect. You also need to use a format string with NSLog, you might even crash there if your line contains any %
characters.
这篇关于警告:正在尝试使用不在框架中的块创建USE_BLOCK_IN_FRAME变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!