cs193p – Assignment #5 Task #3

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

Anywhere a place appears in a table view in your application, the most detailed part of the location (e.g. the city name) should be the title of the table view’s cell and the rest of the name of the location (e.g. state, province, etc.) should appear as the subtitle of the table view cell. The country will be in the section title.

In the Flickr helper class add a couple of new public instance methods which will handle the interface with Flickr:

+ (NSString *)countryOfPlace:(NSDictionary *)place;
+ (NSString *)titleOfPlace:(NSDictionary *)place;
+ (NSString *)subtitleOfPlace:(NSDictionary *)place;
+ (NSArray *)sortPlaces:(NSArray *)places;
+ (NSDictionary *)placesByCountries:(NSArray *)places;
+ (NSArray *)countriesFromPlacesByCountry:(NSDictionary *)placesByCountry;

Continue reading “cs193p – Assignment #5 Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #2

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

Create a UITabBarController-based user-interface with two tabs. The first tab shows a UITableView listing the places obtained above divided into sections by country and then alphabetical within each section. The second tab shows a UITableView with a list of the 20 most recently viewed (in your application) photos (in chronological order with the most-recently-viewed first and no duplicates).

In the iPhone storyboard (ignore the iPad storyboard for now) remove the existing view controller, add a tab view controller, remove the two controllers which arrive with the tab view controller. Add two table view controllers, embed them in navigation view controllers and link those with the tab view controller. Name the tab views and add icons:

cs193p – assignment #5 task #2 - tab bar
cs193p – assignment #5 task #2 – tab bar

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #1

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

Download the data at the URL provided by the FlickrFetcher class method URLforTopPlaces to get an array of the most popular Flickr photo spots in the last day or so. See the Hints for how to interpret data returned by Flickr.

Create a new single-view project. Make it an universal app (to be able to run it on the iPad). Add the Flickr-API to the project by dragging in the provided files (or get them from Shutterbug). Get the API key directly from Flickr and set it in FlickrAPIKey.h.

Create a new sub class from the Flickr fetcher class with a public instance method:

+ (void)loadTopPlacesOnCompletion:(void (^)(NSArray *photos, NSError *error))completionHandler;

Continue reading “cs193p – Assignment #5 Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #6

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

Sort all tables alphabetically (and case insensitively) except the Recents table (which should still be sorted with the most recently viewed first). A good solution to this might involve some of the array sorting methods that use blocks.

… actually the code up to this task already does sorting, but now it will be implemented using blocks.

For the tags create a new property – to do not have to resort everything every time the table needs to display a row:

@property (nonatomic, strong) NSArray *tags;
...
- (void)updatePhotosByTag
{
    ...
    self.tags = [[photosByTag allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];
    }];
}

Continue reading “cs193p – Assignment #5 Task #6”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #5

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

Keep as little of the photos’ image data in the heap as you can (i.e. don’t keep strong pointers to any NSData and/or UIImage objects that you are not currently displaying). You should have at most 2 photos’ image data in memory at a given time, preferably only 1 (or 0 if none are in the process of being viewed or fetched).

The current code up to this task does not keep any strong pointers to NSData or NSImage objects as the image is only stored in the image view. Because the iPad uses a single image view there is at most only one image in memory. The iPhone has two image views thus there could be two images in memory. (Using the profiler proves that behavior)
Continue reading “cs193p – Assignment #5 Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #4

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

Cache photo image data viewed by the user into files in your application’s sandbox. Each photo’s image should be a separate file in the sandbox. Limit the cache’s size to something testable. When this limit is reached, the least recently viewed photos in the cache should be evicted (deleted) to make room for new photos coming in (remember that you can look at a file URL’s resource values to find out when it was last accessed). Your application should never query Flickr for the image data for a photo that it has in its cache (obviously). This cache should persist between application launches.

Before loading an image, check if it is already in the file cache, and load it from there if possible. After the image has been loaded save it to the cache:
Continue reading “cs193p – Assignment #5 Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #3

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

Your primary table view must now have Refreshing enabled (i.e. you can pull down on it to activate the UIRefreshControl). Doing so should refetch the Stanford photo information from Flickr (of course, it’s unlikely to have changed, but refetch anyway).

You could drag out the refresh-control gestures in storyboard (you would have to do it twice) – or create it in code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self
                            action:@selector(loadPhtosFromFlickr)
                  forControlEvents:UIControlEventValueChanged];
    [self loadPhtosFromFlickr];
}

… and move the download code to a new method:

- (void)loadPhtosFromFlickr
{
    [self.refreshControl beginRefreshing];
    ...
    dispatch_async(queue, ^{
        ...
        dispatch_async(dispatch_get_main_queue(), ^{
            ...
            [self.refreshControl endRefreshing];
        });
    }); 
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail