Start out by looking at the Apple documentation for NSArray and NSDictionary. In this case, it looks like the array (an NSArray) contains a number of NSDictionaries.
The data is stored in an nsdictionary and then passed into a nsmuttablearray.
First, I must note that variables in Objective-C are just pointers. When you have a line like this:
NSMutableArray *rows;
You are only saying, “I expect this variable to point to an NSMutableArray.” It is pretty much equivalent to,
id rows;
…and you will not be stopped, at runtime, from putting a regular array in a variable which was declared for mutable arrays (or putting a string in a variable which was declared for a dictionary!). It will work! But your program will crash when you try to do mutable things to a non-mutable array, or dictionary things to a string.
Declaring it as a pointer to an NSMutableArray, instead of id, has a few advantages:
- It lets XCode help you out by autocompleting method names
- It lets the compiler warn you when you try to call methods that NSMutableArray doesn’t have
So, even if your variable is declared as NSMutableArray *rows, on this line:
rows = [[dict objectForKey:@"courses"] retain];
…if the “courses” object was not mutable, what you have in rows is not either. Instead, you can do this:
rows = [[dict objectForKey:@"courses"] mutableCopy];
…to get your own NSMutableArray copy of the array (which you have to release, just as if you retained the original).
You explore the array and dictionaries with standard Cocoa code. Here would be one way to get all of the “Monday” courses:
NSMutableArray *mondayCourses = [NSMutableArray array];
for (NSDictionary* course in rows){
if([[course objectForKey:@"Day"] isEqual:@"Monday"]){
[mondayCourses addObject:course];
}
}
(Warning, I have not run this code.)