是否有一种简单的方法可以将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
}
我想知道是否有一种方法可以使字典键为列名,值为列值。最好不必在一段时间内完成每一行的循环。
答案 0 :(得分:27)
是的:
NSMutableArray *results = [NSMutableArray array];
FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
[results addObject:[appointmentResults resultDictionary]];
}
-resultDictionary
是FMResultSet
上的内置方法,它将当前元组转换为NSDictionary,以列名称为键。