Friday, April 13, 2012

iOS and Threads


While watching the Free Stanford Class Videos About iOS, iPhone, iPad, Objective-C and Xcode, I came across the Blocks and Multithreading lecture.

It does a great job of describing how to avoid locking up the user interface (iPhone or iPad) while the application needs to do something that is time intensive.

In general, one would call the following things in their proper context.

    dispatch_queue_t downloadQueue = dispatch_queue_create("widget download", NULL);
    dispatch_async(downloadQueue, ^{
        
        NSArray *fetchedWidgets = [KTWidgetFetcher widgets];
        NSLog(@"done fetching widgets");

        dispatch_async(dispatch_get_main_queue(), ^{
            
            NSLog(@"UI update is happening");
            self.widgets = fetchedWidgets;
        });
        
    });
    dispatch_release(downloadQueue);

Fun stuff!

Sunday, April 1, 2012

Frames vs Bounds in UIView

In the context of UIView of the iOS, I came across frame and later came across bounds. To the casual observer, one may think they are the same. They are not.

I like how this stack overflow user, amattn, puts it in his post:


Here's the cheatsheet:

    • frame is where the view is (with respect to the superview)
    • bounds is where the view is allowed to draw (with respect to itself)

Also, 40 minutes and 50 seconds into the "4. Views (October 6, 2011) - HD" lecture by Stanford, discusses the difference in depth using a drawing which really helps.