I have a SQLite database that I read items out of feed into a “shopping” object and then add to a NSMutableArray “items” with the following code.
[items addObject:shopping.listName];
[items addObject:shopping.userID];
[items addObject:shopping.listID];
[items addObject:shopping.brandName];
[items addObject:shopping.itemName];
[items addObject:shopping.itemQuantity];
[items addObject:shopping.imageURL];
That works and all, however I then want to get the count of ListName and display all of the records for “ListName” in a UITableview and I can’t figure out how to get just that object out of the Array.
As it is now I can set the number of cell manually or count the entire items array but I have not been able to figure out how to just get the count for “ListName” and only the records for “ListName”
(I think) Every 8th record should be a “ListName” but it seems like running a “for loop” to get out just the records for “listname” is kind of ehh.. I try to stay away from that type of stuff because if I add a record in the future I would have to adjust the indexes and that’s a PITA.
Elegant solution please!
You probably want an array of NSDictionary items. I use SQLite as my backing store and this is how I do it. Essentially, your create a NSDictionary for each record in the table you retrieve. The keys for the NSDictionary are the column names. Then add each record Dictionary to an NSMutableArray. That way, you can access any record by index -> key:
[[items objectAtIndex:index] objectForKey:@"listName"].However, I also notice that you have what looks like a ‘shopping’ object. So you could also just add each individual ‘shopping object’ to the array and access your data like thus: