我從SQLite數據庫獲取行並試圖將它們插入到字典中。除了我不斷收到錯誤!我得到的錯誤「Objective-C指針隱式轉換爲'const id *'不允許使用ARC」我知道這意味着當我添加對象到我的字典時不能使用指針。那麼我該如何解決它,以便將這些數組添加到字典中?從數組添加對象到字典
NSArray *keyArray = [[NSMutableArray alloc] init ];
NSArray *valueArray = [[NSMutableArray alloc ] init ];
NSDictionary* dic;
NSInteger dataCount = sqlite3_data_count(statement);
while (sqlite3_step(statement) == SQLITE_ROW) {
@try {
for (int i = 0; i < dataCount; i ++)
{
NSString* key = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, i)];
NSString *value = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, i)];
if ([value length] == 0)
{
value = @"";
}
keyArray = [keyArray arrayByAddingObject:key];
valueArray = [valueArray arrayByAddingObject:value];
}
}
@catch (NSException *ex)
{
NSLog(@"%@,%@", [ex name], [ex reason]);
}
dic= [NSDictionary dictionaryWithObjects:valueArray forKeys:keyArray count:[keyArray count]];
爲什麼不使用NSMutableArrays?你的錯誤究竟在哪裏? – ohr 2012-07-30 18:00:05
你在哪一行得到錯誤 – 2012-07-30 18:00:08
'0'長度字符串已經是'@「」',並且不需要檢查該值。如果你正在檢查'NULL',那麼你需要檢查'sqlite3_column_text'的值,因爲'stringWithUTF8String:'會在'NULL'值上崩潰。 – Joe 2012-07-30 18:06:31