Posterous theme by Cory Watilo

MessagePack parser for Objective-C / iPhone

This is a wrapper for the C MessagePack parser, as an easy to use bridge to Objective-C, which my employer has graciously permitted us to open source:

https://github.com/chrishulbert/msgpack/tree/master/objectivec

In a similar way to the JSON framework, this parses MessagePack into NSDictionaries, NSArrays, NSNumbers, NSStrings, and NSNulls.

It contains a small patch to the C library so that it doesn't segfault with a byte alignment error when running on the iPhone in armv7 mode.

If you're using JSON or XML to communicate from your servers to your iPhone app, you should strongly consider using MessagePack for size and speed: in our tests, gzipped MessagePack was roughly half the size of gzipped JSON, and is much faster to parse to boot.

What do do with EXC_ARM_DA_ALIGN on an iPhone app

Recently got the following nasty notices in a crash report on an iphone app:

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: EXC_ARM_DA_ALIGN at 0x078e0032

Turns out that ARMv7, which is now compulsory, has memory alignment issues that ARMv6 didn't, so now people will probably see more of these issues.
Anyway, i could write about it, or i could post some links to helpful blogs:

Basically, replace code like this: 

destination = *((long *)unalignedPointer);

With this:

long tmp;
memcpy(&tmp, unalignedPointer, sizeof(tmp));
destination = tmp;

Staining the boat

I've finally got the boat hull to the point where i'm ready to apply the finish to it. Here you can see i've been busy staining it. What i haven't shown you is the problem where when i first stained it, the stain soaked through to the glue and partially dissolved it, and the deck started peeling away from the glue. So i had to re-putty it, sand it, and restain it.

(download)

Iphone gesture recogniser that works for baby games

I've been annoyed lately at the number of baby apps that don't seem to work when my daughter is playing with my iphone. Seems that the problem is that they only expect one finger, but if bubby is holding the phone with one hand on the screen and taps it with her other hand, it doesn't work. Or if she taps it with more than one finger, or if she swipes instead of tapping, or doesn't get it 'just right'.

So to that end, i've made a UIGestureRecogniser that works for any old tap, especially for baby games for the iphone:

And you use it like so, in your view controller:






- (void)viewDidLoad {


    [super viewDidLoad];


 


    BabyTapGesture *bub = [[[BabyTapGesture alloc] initWithTarget:self action:@selector(tap)] autorelease];


    [self.view addGestureRecognizer:bub];


 


}


 


- (void) tap {


    NSLog(@"Tapped!");


}
<div>

NSMutableSet with weak references in objective-c

Recently i've needed to implement the 'observer/notifier' pattern (is that what it's called?) in objective-c for an iphone app. The gist of this is that I need for my notifier to keep track of a set of observers.

However, due to the nature of reference counting (we're not garbage collected), this set of observers must hold weak references, and the observers' dealloc method must make a call to the notifier, telling it to remove the observer from the set. Without the weak reference, the observer will never be freed, and we have a memory leak.

Now the NSMutableSet always retains any object that it contains, so it's not much help. So here's my set that only holds weak references:

And here's an example of using it. The logged output from this test should all be 1's for the retain count:



NSString *col = [NSString stringWithFormat:@"Blue"];


NSLog(@"Colour retain: %d", col.retainCount);


WeakReferenceSet *set = [WeakReferenceSet set];


[set addObject:col];


NSLog(@"Colour retain: %d", col.retainCount);


[set addObject:col];


[set addObject:col];


[set addObject:col];


NSLog(@"Colour retain: %d", col.retainCount);


[set removeObject:col];


NSLog(@"Colour retain: %d", col.retainCount);


[set removeObject:col];


[set removeObject:col];


[set removeObject:col];


NSLog(@"Colour retain: %d", col.retainCount);


[set addObject:col];


NSLog(@"Colour retain: %d", col.retainCount);


[set removeAllObjects];


NSLog(@"Colour retain: %d", col.retainCount);


Image manipulation pixel by pixel in objective C for the iphone

Recently needed to manually edit the pixels on a UIImage so i could apply, in my case, a colourising filter ("colorizing" for most of you reading this!)

Anyway, couldn't find many good tuts on the web, so here we go with my code. Tested and works great in xcode 4.2 / iphone.

Here's my end result. You may recognise a yamaha FZ1N. Lovely bike, wish i'd never sold it:

Colourise

And here's the code:

Baby Allergy Tracker

Allergytracktrans
This app is aimed at helping you keep track of which foods you have fed your newborn child, so that you can pinpoint any potential allergies.

Available in the app store!

Screenshots

(download)

Untried foods

This is where you can view your 'to-do' list of foods that you haven't tried yet.

When you feed your child a food, tap it in this list and select 'Mark as tried'. The food will then be removed from this list and appear on the 'Tried foods' list.

To add a new food, tap the '+' button in the top right.

To remove a food, swipe across its and tap delete.

Tried foods

This is where you can see your list of foods that you have tried, and take notes if your child has a suspected reaction.

To take notes if you suspect your child has had a reaction to a food, tap it in this list and select 'Reaction notes'.

Any foods that you have made any notes against will appear orange in this list.

To remove a food from this list and return it to the untried foods list, tap it and select 'Move back to untried'.

Reaction list

This is for viewing just the foods that have reaction notes in a convenient list.

To view further details about any food, simply tap its name in this list.

Important

Remember that this app is no substitute for professional medical help. You must consult with your family doctor, pediatrician, or nurse if you suspect your child is having an allergic reaction, or if your family has a history of allergies.

About

This app was lovingly crafted by Chris Hulbert (Splinter Software) for his wife and soon-to-be child. You can get in touch via email with any suggestions for how to improve this app.

See my other apps.

Icon by Laura Design.

Toolbar icons from app-bits.

Power sanding the deck

I've been busy power sanding the edge of the deck flush with the side using a mouse sander, just to tidy up what the planer couldn't really get perfect. Last photo you can see i've puttied it up, ready for some hand sanding. Then it should be good for stain and clearcoat.

(download)