以下代码
NSMutableString *a = [[NSMutableString alloc] init];
NSMutableString *pivot =[[NSMutableString alloc] init];
int i= 0;
for ( i = 0; i < [columns count]; i++)
{
if ([[[data objectForKey:pivot] class] isKindOfClass:[NSNumber class]])
{
sqlite3_bind_int(sqlStatement, i+1,[[columns objectAtIndex:i] integerValue]);
}
else
{
// NSLog(@"kind of class %@ %@",NSStringFromClass([[data objectForKey:pivot] class]) ,[data objectForKey:pivot]);
[pivot setString:[columns objectAtIndex:i]];
[a setString:(NSString*)[data objectForKey:pivot]];
sqlite3_bind_text(sqlStatement, i+1, [a UTF8String], -1, 0);
}
}
a = nil;
pivot = nil;
引发异常
kind of class __NSCFConstantString
-[__NSCFNumber length]: unrecognized selector sent to instance 0xc94c240
但是日志清楚地表明这[data objectForKey:pivot]
是一个字符串!并且test
变量始终为0!
我检查了调试,实际上 [data objectForKey:pivot]
是一个数字。事实上,我使用一个if
(未显示)来检查它是否是一个数字。显然,if
失败...