Archive for May, 2011


The MD5 checksum bug identified.

Happily it’s easy to fix and exactly what I thought it was. When retrieving values from an NSManaged object like so:

NSString *foo = recipe.value;

or

NSString *foo = [recipe valueForKey:@"value"];

If the value is not present you get a nil. Messages to nil go nowhere but do not crash, so if value should have been an NSString the following is OK:

[foo isEqualToString:@"bar"]

However if the object you are retrieving from is an NSDictionary you will get an NSNull. NSNull is a class and a valid object so sending it messages it does not understand will fail:

NSString *foo = [dictionary valueForKey:@"value"];
[foo isEqualToString:@"bar"]; // CRASH

Seeing as I need to compute the md5 sum for a dictionary based recipe and an managed object based one and the sums need to be the same the code that produces the string to hash must produce identical results. In the case of a null value the code to produce the key to hash from the recipe managed object inserted this:

(null)

The code to produce it from the dictionary simply crashed. So I changed it in both the dictionary and the managed object routines to check:

if ([object isEqualToClass:[NSNull class]]) {
object = @"";
}

Which meant the keys changed and I didn’t update the initial data set to reflect that as I didn’t run OCUnit and thus didn’t get bashed upside the head that something had changed.

Always run your unit tests folks.

So the latest version of my main app is in the app store and…. it has a minor minor bug.  In a rush to eliminate a highly unlikely, in fact to pre-empt, a bug I updated some code to check for the possibility of NSNull being assigned to an NSString.  For some reason this changed the md5 sum assigned to two recipes (Shepherd’s Pie and Seafood Linguine Carbonara) which means they will be duplicated for every user I expect.  Shame.  Not life ending but annoying.  I submitted the update metadata around 21:20 on Friday, the app at around 21:57.  I fixed the bug at 21:45.  I didn’t run the OCUnit tests which would have spotted the md5 checksum changing when it should not have.

Easy to fix though and on the upside all of this code and unit tests means development is much faster now.  So I’m well on the way to iTunes document synchronisation support.  I’ve had to relocate a plist file and the sqlite database out of documents and into library otherwise they show up in iTunes.  So all you people that write core data tutorials putting sqlite in the documents folder… stop it!  It’s not a good idea use NSLibraryDirectory instead of NSDocumentDirectory when calling NSSearchPathForDirectoriesInDomains.

On another note, to determine what files were new in the documents folder I thought I’d use file info, like dates etc.  Figuring that when the file is written to the iPhone by iTunes it would write a new file but it doesn’t… it preserves the host machines modified and creation dates:

      NSDictionary *fileInfo = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
                                                                                error:nil];
      NSDate *lastModified = [fileInfo valueForKey:NSFileModificationDate];

(gdb) po fileInfo
{
    NSFileCreationDate = "2011-05-09 11:30:53 +0000";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = 501;
    NSFileGroupOwnerAccountName = mobile;
    NSFileModificationDate = "2011-05-09 11:30:53 +0000";
    NSFileOwnerAccountID = 501;
    NSFileOwnerAccountName = mobile;
    NSFilePosixPermissions = 420;
    NSFileProtectionKey = NSFileProtectionNone;
    NSFileReferenceCount = 1;
    NSFileSize = 1788192;
    NSFileSystemFileNumber = 2608135;
    NSFileSystemNumber = 234881027;
    NSFileType = NSFileTypeRegular;
}

A shame but totally understandable as the file is not being modified or created as such. Looks like I’ll need to track a bit more metadata myself or waste time import/exporting everything every time. Err… no.

Roger Hargreaves 76th Birthday – Google Logos

Google have celebrated Roger Hargreaves 76th birthday with a whole stack of Mr. Men logos. As far as I can discern from the javascript there are 16 of them, after the cut. View full article »

Recipe for Tunnock Cakes (Marshmallow Teacakes)

I cooked this yesterday, just a little to late to make it into the current build of the app. Either way no photos here just the basic ingredients and steps, after entering everything into the app the easiest way to just post the recipe here was to cut and paste from an app generated PDF:

Finished Tunnock

Nom nom nom

Recipe Below View full article »

Viewing the MySQL dump import progress

A really useful linux shell hint from someone elses blog… stumbled across browsing recommended in google reader:

Viewing the MySQL dump import progress.

Small linux utility called ‘bar’ which provides a progress bar for any program that can use a pipe for input…. e.g.:

bar if=foo.sql | mysql -u user -p database

Nice… dd esq CLI by the look of it.

Powered by WordPress | Theme: KLG based on Motion by 85ideas.