iphone - 奇怪的 NSString 行为 "warning: Unable to read symbols for..."

标签 iphone objective-c xcode nsstring

我有一个处理数据库操作的对象。它开始于:

-(id)init{
    databaseName = @"WhoPaidLast.sql";

    // I think this one gets it from the app whereas the next one gets it from the phone
    // databasePath = [[NSBundle mainBundle] pathForResource:@"WhoPaidLast" ofType:@"sql"];

    // Get the path to the documents directory and append the databaseName
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    self.databasePath = [documentsDir stringByAppendingPathComponent:databaseName];

    // Execute the "checkAndCreateDatabase" function
    [self checkAndCreateDatabase];

    return self;

最后我检查数据库:

-(void) checkAndCreateDatabase{
    // Check if the SQL database has already been saved to the users phone, if not then copy it over
    BOOL success;

    // Create a FileManager object, we will use this to check the status
    // of the database and to copy it over if required
    NSFileManager *fileManager = [NSFileManager defaultManager];

    // Check if the database has already been created in the users filesystem
    success = [fileManager fileExistsAtPath:self.databasePath];

    // If the database already exists then return without doing anything
    if(success) return;

    // If not then proceed to copy the database from the application to the users filesystem

    // Get the path to the database in the application package
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];

    // Copy the database from the package to the users filesystem
    [fileManager copyItemAtPath:databasePathFromApp toPath:self.databasePath error:nil];

    //[fileManager release];
}

在此之后,当我去使用 databasePath 时,我似乎只能在它抛出此错误之前使用它一次:

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

我有一个从数据库返回一堆值的函数。第一次使用 detabasePath 它工作正常并输出预期值,第二次它抛出上述错误。

这是该函数的开头:

// Setup the database object
    sqlite3 *database;

    // Init groupsArray
    groupsArray = [[NSMutableArray alloc] init];


     NSLog(@"r- %@",self.databasePath);
     NSLog(@"s- %@",self.databasePath);
    // Open the database from the users filessytem
    if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) {

如果我删除第二个 NSLog 函数,那么在下次使用 databasePath 时它会出错。如果我同时删除两者,它将对 sqlite3_open 函数起作用,但在下次使用时出错。

如果有人知道我的错误来源和/或我可能做错了什么,我将非常感谢您的帮助。

谢谢。

最佳答案

上面的代码中似乎存在一些与内存管理相关的错误。我猜您看到的调试器错误是由于与内存相关的崩溃造成的,调试器无法完全捕获它来为您提供堆栈跟踪。

首先,您的 -init 方法从不在父类(super class)上调用它,这是不对的。你需要有类似的东西

if (!(self = [super init]))
{
    return nil;
}

在该方法的开头。

仅此一项就应该导致各种有趣的崩溃。除此之外,确保 databasePath 属性设置为使用 copyretain(最好是 copy,因为它是一个 NSString),否则它不会保留 [documentsDir stringByAppendingPathComponent:databaseName] 返回的自动释放对象。

此外,我知道您已将其注释掉,但不要使用 [fileManager release]。这是您从 [NSFileManager defaultManager] 返回的共享实例,但您没有保留它,因此释放它会导致不好的事情。

您可以尝试启用断点并打开 NSZombie 以查找特定的崩溃位置,但我敢打赌原因是我上面列出的因素之一。

关于iphone - 奇怪的 NSString 行为 "warning: Unable to read symbols for...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6156689/

相关文章:

iphone - 如何在移动 Safari 中计算可视区域的高度(即窗口高度减去地址和书签栏)?

iphone - 在iphone应用程序开发中如何添加两个uiimageview并将其保存到iphone照片库?

iphone - 仅在归档时出现链接器错误

ios - MPMoviePlayerController initWithContentURL 延迟按钮点击

iphone - 用图像覆盖 MKMapView

iphone - NSScanner 在简单删除空格时的奇怪行为

ios - 如何使用 PHPicker 从图库中获取 WebP 图片

ios - iPad Pro 第三代无缘无故杀死前台应用程序

iphone - iOS Quartz 在 pdf 中嵌入字体

ios - 从父类(super class) UIView 连接的 IBoutlet 仍然为零