I am new to objective-c and I am trying to create an array of dictionaries in an effort to view them in a NSTableView with three columns. the sqlite DB schema has three columns as well, “foo”, “bar”, and “foobar” in a table called “tbl1”. i am using FMDB as a wrapper, and i can write and query successfully.
i can create an array for the entire DB with this:
FMResultSet *rs = [db executeQuery:@"select * from tbl1"];
and i can create a dictionary with this:
dict = [[NSMutableDictionary alloc] init];
[dict setObject: @"baz"
forKey: @"foo"];
reading each item in the DB works:
while ([rs next]) {
NSLog(@"%@, %@, %@",
[rs stringForColumn:@"foo"],
[rs stringForColumn:@"bar"],
[rs stringForColumn:@"foobar"]);
}
however, i cannot seem to create a single array of NSMutableDictionaries so I can read them into a cell-based table view. i was able to populate a single column with the identifier “foo” with the values for “foo”, however, that was just by making an array of “foo” items from an SQL query:
FMResultSet *rs = [db executeQuery:@"select * from tbl1"];
while([foo next]) {
NSString *thisFoo = [foos stringForColumn:@"foo"];
[_foos addObject:[NSString stringWithFormat:@"%@", thisFoo]];
}
NSLog(@"Foos: %@", _foos);
as a side note, i should be using mutable arrays and mutable dictionaries if i want to update the DB later? or will it not matter, as i would have to query the entire DB to refresh the table view anyway?
any suggestions on how to populate a three column tableview with a three column sqlite DB are appreciated – as well as corrections to my understanding of FMDB or tableviews.
should give you the array of dictionaries