有没有一种简便的方法可以将executeQuery:SELECT * ...的FMDB结果轻松放入字典中?

FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
    //Create dictionary
    //Add dictionary to array for later use
}

我想知道是否有一种方法可以使字典关键字成为列名,而值成为列值。最好不必在while内遍历每一行。

最佳答案

是的:

NSMutableArray *results = [NSMutableArray array];

FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
  [results addObject:[appointmentResults resultDictionary]];
}
-resultDictionaryFMResultSet的内置方法,它将把当前元组转换为NSDictionary,并以列名作为关键字。

关于objective-c - FMDB结果集到字典中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9405059/

10-12 16:30