cs193p – Assignment #6 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

If you were to use your application for weeks, your database would start to get huge! Implement a mechanism for pruning your database over time. For example, you might want to delete photos a week after you download them?

Add an additional date attribute created to the Photo entity to store when a photo has been added to the database. (Don’t forget to recreate its sub class).

Set the new attribute when a photo is added:

+ (Photo *)photoWithFlickrInfo:(NSDictionary *)photoDictionary
        inManagedObjectContext:(NSManagedObjectContext *)context
         existingPhotographers:(NSMutableArray *)photographers
               existingRegions:(NSMutableArray *)regions
{
    ...    
    photo.created = [NSDate date];
    ...
}

Continue reading “cs193p – Assignment #6 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

Loading Flickr information into your database can be ridiculously inefficient if, for each photo you download, you query to see if it is already in the database, add it if it is not (and maybe update it if it is). Enhance your application to make this download much more efficient, preferably only doing two or three queries total in the database for each “batch” of Flickr photos you download (instead of hundreds, which is what Photomania does). The predicate operator IN might be of value here.

Let’s start by limiting the photo queries, but only if there any photos. If there are none, the request containing a predicate with an IN operator and nil will most likely crash … A mystical helper method (described a little bit later) generates an array of photo IDs used to query the database. If there are matches, create a new array of Flickr photo dictionaries containing only photos not yet in the database. Replace the current photos array buy the new – reduced – one:
Continue reading “cs193p – Assignment #6 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Extra Task #1

Please note, this blog entry is from a previous course. You might want to check out the current one.

Still allow the user to force a fetch using the refreshControl in the appropriate table views. And use the cellular network to fetch only when the user prompts you via a refreshControl in this manner (otherwise restrict all your URLforRecentGeoreferencedPhotos fetches to WiFi only). If you are a bit stumped about how to know when to endRefreshing in a table view, think about whether there are some NSNotifications flying around that you could listen in on.

The refresh-control view is handled by the regions-table-view controller. The downloads are handled by the application delegate. To communicate between those two classes use notifications. The table-view controller will post a notification when a new cellular download should start. It will listen to another notification to know when the download has been finished. The application delegate will listen for the first notification and start the download. It will post the second notification when the download has finished.
Continue reading “cs193p – Assignment #6 Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Tasks #9 to #11

Please note, this blog entry is from a previous course. You might want to check out the current one.

Assignment #6 Task #9

Do not store Flickr photos themselves (i.e. any image other than a thumbnail) in your Core Data database. Fetch them from Flickr on demand each time.

… well we don’t, so nothing to do there …

Assignment #6 Task #10

Your application’s main thread should never be blocked (e.g. all Flickr fetches must happen in a different thread). You can assume Core Data will not significantly block the main thread.

… we made sure of that earlier …

Assignment #6 Task #11

Your application must work in both portrait and landscape orientations on both the iPhone and the iPad and it must work on a real iOS device (not just the simulator).


… it worked for the previous assignment, we did not change anything which could make a difference … and we also checked …

The complete code for all mandatory tasks is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Task #8

Please note, this blog entry is from a previous course. You might want to check out the current one.

Display a thumbnail image of a photo in any table view row that shows Flickr photo information. You must download these on demand only (i.e. do not ask for a thumbnail until the user tries to display that photo in a row). Once a thumbnail has been downloaded, you must store the thumbnail’s data in Core Data (i.e. don’t ask Flickr for it again). Don’t forget that table view cells are reused!

Because we have already prepared the Core-Data schema, and saved the URL for the thumbnail with the photo data, this ones is quite easy.

Set the image of cell to thumbnail stored in Core Data. If there is none, nothing will be shown, but we need to download it asynchronously. As soon as it has been downloaded store it in Core Data (in the corresponding context) and tell the view to update:
Continue reading “cs193p – Assignment #6 Task #8”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #10

Please note, this blog entry is from a previous course. You might want to check out the current one.

Assignment #6 Task #5

All of your table views everywhere in your application (including the Recents tab) must be driven by Core Data (i.e. not NSUserDefaults nor Flickr dictionaries). You no longer have to support “pulling down to refresh” (though see Extra Credit 1).

To handle the recent entity of the database schema, create another category, containing a single class method:

+ (Recent *)recentPhoto:(Photo *)photo;

Continue reading “cs193p – Assignment #6 Part #10”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #9

Please note, this blog entry is from a previous course. You might want to check out the current one.

Photos Table & Image View

Assignment #6 Task #4

When a region is chosen, all the photos in your database that were taken in that region should be displayed (no sections are required). When a photo is then chosen, it should be displayed in the same way photos were displayed in last week’s assignment.

Like in the last part, clear out the generic photo-table-view controller. For now it needs only a single method to setup the table cells using the photo data:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Photo Cell"];
    
    Photo *photo = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = photo.title;
    cell.detailTextLabel.text = photo.subtitle;
    
    return cell;
}

Continue reading “cs193p – Assignment #6 Part #9”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail