7 Jul 2011, 9:18am
/dev/random
by

leave a comment

Measuring Slow Code in Objective-C

A note to myself, because I can never remember how to do this:

    NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
    ...operation here...
    NSTimeInterval duration = [NSDate timeIntervalSinceReferenceDate] - start;
    NSLog( @"%f", duration  );
1 Jul 2011, 6:34pm
/dev/obj-c
by

1 comment

UIViewController Calling loadView() Multiple Times

I don’t know if this is one of those things that everyone else doing iPhone development automatically knows and I don’t, or if it’s an obscure, esoteric gotcha. It certainly did kill a bunch of my time today.

Turns out that a subclass of UIViewController doesn’t create a default UIView when instantiated. I discovered that by watching my controller’s loadView method get called multiple times (a dozen in fact) before crashing when I tried to add an instance of UIButton to the non-existant base view.

It seems that adding this at the beginning of loadView is the solution:

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    self.view = view;
    [view release];

After that everything was great and trying to add the button no longer crashed the app.

1 Jul 2011, 4:06am
/dev/random
by

leave a comment

Living Code

Long, long ago I posted Better Range Intersection in Ruby, which was Dan’s improved solution to my solution for finding intersections across date ranges.

Two years and 3,100 pageviews later, Montgomery Kosma came across that post, found a bug in it, provided a solution and immediately improved it’s quality. I love it when that happens!