LoginSignup
7
7

More than 5 years have passed since last update.

FMDBのresultDictionaryが取得できない件

Posted at

Objective-CのSQLITEラッパー「FMDB」には「resultDictionary」というメソッドがあると聞きました。
FMDBではselect文を投げたらFMResultSetで返ってきますが、それをNSDictionaryに変換できるそうです。

しかしこれがうまくいかない。

FMResultSet *results = [_db executeQuery:SQL];
NSDictionary *dic = [results resultDictionary];

このように取得しようとしてもdicはnilになります。
小一時間悩んで行き着いた正解はこちら。

FMResultSet *results = [_db executeQuery:SQL];
while ([results next]) {
    NSDictionary *dic = [results resultDictionary];
}

考えてみたらFMResultSetは配列(のようなもの)に辞書(のようなもの)が入ってるので、当たり前といえば当たり前ですけどね。

このdicをArrayに放り込んだら扱いやすい配列のできあがりです。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7