问题描述
||
我有一个处理数据库操作的对象。它以以下内容启动:
-(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
方法永远不会在超类上调用此方法,这是不对的。你需要有类似的东西
if (!(self = [super init]))
{
return nil;
}
在该方法开始时。
仅此一项便会导致各种有趣的崩溃。除此之外,请确保将databasePath
属性设置为使用copy
或retain
(最好是copy
,因为它是NSString),否则它不会保留[documentsDir stringByAppendingPathComponent:databaseName]
返回的自动释放对象。
另外,我知道您已将其注释掉,但不要使用[fileManager release]
。那是您从ѭ12中取回的共享实例,并且尚未保留,因此释放它会导致不好的事情。
您可以尝试启用断点并打开NSZombie来查找特定的崩溃位置,但是我敢打赌,原因是我上面列出的因素之一。
, 这是iOS / Xcode 4的错误
在终端中输入以下2条命令
cd /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1\\ \\(8G4\\)/Symbols/
sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/Developer/ Developer
在运行之前清理(shift + cmd + k)项目。问题应该解决。
参考:http://blog.damore.it/2011/04/xcode4-debugging-problem-warning-unable.html