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

cs193p – Assignment #5 Task #2

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

The user-interface should always be giving some indication (e.g. a UIActivityIndicatorView) to the user when the currently displaying user-interface is going to show something when some active thread finishes. The network activity indicator in the status bar is not sufficient for this, but your application should also turn on the networkActivityIndicator whenever it is accessing the network (and only then).

The table view will use the refresh-control feature in the following thus – there is no need to put an extra activity indicator there for now.

Change in both storyboards the background of the scroll views to black (which is a cosmetic change only) … the rest will be done in code to avoid having to duplicate everything for both storyboards.
Continue reading “cs193p – Assignment #5 Task #2”

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.

Your application must implement all the required tasks from the last assignment (and all the required tasks in this assignment) without doing any Flickr fetching or file system interactions in the main thread. Your user-interface should be responsive to the user at all times (i.e. the main thread should never be blocked).

Flickr is accessed twice. First when the data is loaded to populate the first table. Create a new dispatch queue and load the photos there. As soon is this is done return to the main queue and set the photos property:

- (void)viewDidLoad
{
    [super viewDidLoad];    
    dispatch_queue_t queue = dispatch_queue_create("Flickr Downloader", NULL);
    dispatch_async(queue, ^{
        NSArray *photos = [FlickrFetcher stanfordPhotos];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.photos = photos;
        });
    });
}

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

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #11 – Multithreading and Persistence

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

Lecture #11 continues with multi threading and provides more insight into Grand Central Dispatch. It shows how to use refresh control, activity indicators and the network activity indicator. … incorporating all of that in Shutterbug …

The second half of the lecture addresses persistence, using archiving, SQLite and/or the file system.

The code of the demo is available at Stanford and on github.

Slides are available on iTunes …..

The lecture is available at iTunes and is named “11. Multithreading and Persistence (February 12, 2013)”.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #4 Extra Task #2

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

Make your application work on the iPad as well with appropriate user-interface idioms on that platform. This will require you to have absorbed the lecture immediately after this was assigned. But you’ll be asked to do this next week anyway, so you’ll be ahead of the game if you do it this week (and get a little bit of extra credit for doing it early).

In the iPad storyboard remove the default controller. Drag out a new split-view controller. Remove the default master and detail views. Go to the iPhone storyboard copy every thing and paste it to the Pad storyboard. Set the tab-view controller to be the master view controller. Remove the segues pointing to the image view controller and set the image view as detail view controller:

cs193p - assignment #4 extra task #2
cs193p – assignment #4 extra task #2

Continue reading “cs193p – Assignment #4 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail