Objective c BWDB SQLLite包装发布错误
我正在我的应用程序中使用比尔·温曼(Bill Weinman)BWDB的最新ARC版本,它在调试中运行良好。然而,在发行版中它崩溃了。而且只有在真实设备上,在模拟器中,它才能正常工作。我试过Lynda.com上最新的BWDB EXERSSE文件,它也崩溃了 我发现,在forin循环中,当您枚举结果时,指向行的指针已经被释放Objective c BWDB SQLLite包装发布错误,objective-c,sqlite,Objective C,Sqlite,我正在我的应用程序中使用比尔·温曼(Bill Weinman)BWDB的最新ARC版本,它在调试中运行良好。然而,在发行版中它崩溃了。而且只有在真实设备上,在模拟器中,它才能正常工作。我试过Lynda.com上最新的BWDB EXERSSE文件,它也崩溃了 我发现,在forin循环中,当您枚举结果时,指向行的指针已经被释放 for (NSDictionary *firstSpecies in [sql getFirstSpeciesName]) { //firstSpecies is al
for (NSDictionary *firstSpecies in [sql getFirstSpeciesName])
{
//firstSpecies is already released here
m_speciesName = [firstSpecies objectForKey:@"FirstSpeciesName"];
}
这让我相信在执行过程中存在某种错误
(NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len
或在枚举行变量中
你知道怎么解决这个问题吗
“不安全”和“不安全”都会阻止对象保留,但方式略有不同。对于_弱,指向对象的指针将在其指向的对象解除分配时转换为nil,这是非常安全的行为。顾名思义,uuu unsafe_uunrepaired将继续指向对象所在的内存,即使在对象被释放之后也是如此。这可能会由于访问解除分配的对象而导致崩溃
在BWDB示例中,有一行存储在枚举函数中的实例变量enumRows中
- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len
{
if ((*enumRows = [self getPreparedRow]))
{
state->itemsPtr = enumRows;
state->state = 0; // not used, customarily set to zero
state->mutationsPtr = state->extra; // also not used, required by the interface
return 1;
} else {
return 0;
}
}
enumRows定义为:
__unsafe_unretained NSDictionary * enumRows[1];
NSDictionary * enumRows;
方法GetPreparedRow的声明如下:
- (NSDictionary *) getPreparedRow
{
int retCode = sqlite3_step(m_statement);
if (retCode == SQLITE_DONE)
{
sqlite3_finalize(m_statement);
return nil;
}
else if (retCode == SQLITE_ROW)
{
int col_count = sqlite3_column_count(m_statement);
if (col_count >= 1)
{
NSMutableDictionary * dRow = [NSMutableDictionary dictionaryWithCapacity:1];
for(int i = 0; i < col_count; i++)
{
NSString * columnName = [NSString stringWithUTF8String:sqlite3_column_name(m_statement, i)];
[dRow setObject:[self columnValue:i] forKey:columnName];
}
return dRow;
}
}
else
{
NSLog(@"rowFromPreparedQuery: could not get row: %s", sqlite3_errmsg(m_database));
return nil;
}
return nil;
}
我改变了枚举函数,只是为了设置一个指向这个强枚举行指针的uuu不安全的u未恢复指针
Bill Weinman的BWDB针对iOS 7进行了更新,这也可以解决问题 RSSDB.m ios7sdk中的一个bug阻止它在ARM上工作
// for (row in [self getQuery:@"SELECT id FROM feed ORDER BY LOWER(title)"]) {
// [idList addObject:row[@"id"]];
// }
iOS 7的变通方法
[self prepareQuery:@"SELECT id FROM feed ORDER BY LOWER(title)"];
while ((row = [self getPreparedRow])) {
[idList addObject:row[@"id"]];
}
@丹妮
如果我定义
NSDictionary * enumRows;
然后
(NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len
{
if ((enumRows = [self getPreparedRow]))
{
__unsafe_unretained id row = enumRows;
state->itemsPtr = &row;
...
我收到1个警告和1个错误(编译前):
不兼容的指针类型正在使用“NSDictionary*”类型的表达式初始化“\uuuu unsafe\u unrepaired”[1]
ARC不允许将间接指针隐式转换为Objective-C指针您应该在BWDB网站上发布此问题。我已经发布了,我也临时修复了它
(NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len
{
if ((enumRows = [self getPreparedRow]))
{
__unsafe_unretained id row = enumRows;
state->itemsPtr = &row;
...