Latest Entries

Populating NSDictionary from an item property in NSArray

Occasionally I’ll find myself wanting to convert an array of objects into a dictionary where the dictionary is keyed off one of the properties of the objects in the array. Typically this is a 3-liner that looks something like:

NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (Foo *f in container) {
    [dictionary setObject:f];

In the above example, “container” is an NSArray of “Foo” objects that have a property “bar.”

That’s easy enough, but with some KVO magic we can reduce this to a single line:

NSDictionary *dict = [NSDictionary dictionaryWithObjects:container 
                                                 forKeys:[container valueForKeyPath:@"bar"]];

The meat of this line is valueForKeyPath which will return an array containing the results of calling -[Foo bar] on each object.

Nothing monumental, but still cool eh?

Let’s try this again…

How many times can a blog be resurrected? I suppose at least one more…

One of the things I’ve discovered since entering the “real world” is programming all day can be draining. Even though I enjoy building software in my free time, by the time I get home usually I just want to veg out. Nevertheless, I’ve had some pet projects in the back of my mind for a while and they won’t go away. I’ve tried a few different methods of overcoming my mental block, but I haven’t had any success yet.

So here I am again… My new hypothesis is that sharing my progress will help motivate me complete my goals by:

1) Forcing me to break projects into milestones

I’m not sure if it’s just me, but when I’m working on my own projects I tend to focus too much on what’s left to do. I’m don’t think that’s the best approach (especially for larger projects). Forcing myself to break projects into milestones will help me quantify my results into digestible chunks.


2) Appreciate progress made so far

This sort of piggybacks on the first item, but I think it’s important. The thought here is posting periodically will remind me I am making progress. It’s a marathon, not a sprint.


3) Creating a sense of responsibility from exposing my progress to more than just myself

This may be vain, but exposing my progress to the public will more than likely make me feel the need to finish so as to not let anyone else down. After all, that would be embarrassing.


I guess that’s it. Here’s to another blog resurrection! :cheers:

Single UIView with rounded corners and drop shadow

* blows the dust off the blog *

Now that that’s out of the way… I’ll get right to it.

The other day at work I needed to make a view that had both rounded corners and a drop shadow. I realized that setting the properties on a single CALayer object wouldn’t be sufficient since setting the corner radius required masksToBounds to be enabled, but masking would cut out the shadow. What to do?

There are a couple different solutions. I first thought of using two views: a parent and a child. The parent view would display the shadow and the child would have the rounded corners. While this works, it’s a nuisance to set up.

The solution I came up with was using drawRect for filling the UIView’s background color and then setting the layer properties for the shadow. I’ve included a little code below illustrating how I did it:

NOTE: This method won’t work if your view needs to clip subviews.

In your view’s .m file:

- (id)initWithFrame:(CGRect)frame
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.layer.shadowColor = [UIColor blackColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(0, 0);
        self.layer.shadowOpacity = 1.0;
        self.layer.shadowRadius = 2.0;        
    return self;
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
    CGContextRef context = UIGraphicsGetCurrentContext();
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:6];
    [[UIColor greenColor] set];
    CGContextAddPath(context, path.CGPath);

We set the layer’s shadow properties in the init method and then when drawRect is called, we fill the rounded path with our background color of choice.

Pitch Detection in iOS 4.x

Pitch detection is a relatively common thing to do in the audio realm. After scouring the web I found a lot of useful Core Audio resources, but nothing directly related to pitch detection. In my searching I also found others who seemed to be looking for a way to do this. I decided to write a little app which demonstrates how pitch detection can be accomplished in iOS.

This is my first real tutorial so feedback is greatly appreciated. If you find this tutorial useful, let me know!



Continue reading…

Android “Binder Transaction Failed!” Error Message

This little gem of an error is actually one of the main catalysts in me starting this website!

I was working on some Android cross-process code at work the other day when I came across this error. I was trying to place an image file I had acquired from the camera into a Bundle and sending it from one process to another. When I saw it wasn’t working I checked LogCat only to find a pretty non-descriptive error reading something along the lines of “Binder transaction failed!”

I searched high and low for the cause of this error with little success. Finally found out the answer on the Android-Developers google group (I don’t have the link anymore, but if there are enough requests I’ll go find it).

The problem is that for cross-process communication, a Bundle cannot hold more than roughly 100 kilobytes before the transaction fails! I understand why this is the case, but it would have been nice to have a slightly more descriptive error message!

Silly Story Maker for iPhone and iPad

Silly Story Maker is a fun, educational sentence making game for the iPhone and iPod Touch! I used to have a toy similar to this as a kid and I thought it’d be fun to bring the joy I had playing with that toy to the next generation! For more info check out the the iTunes page.

Let’s get started!

Hi all, over the next week or so I’ll be migrating my old site,, to here. You’ll also be seeing some (hopefully pleasing) aesthetic changes to better match the image I had in my head when I bought this domain.

Copyright © 2004–2012. All rights reserved.

RSS Feed.