Safari 4.0 incompatible with Find It! Keep It!

June 8th, 2009

Just a quick note to mention that Find It! Keep It! is not compatible with Safari 4.0. When you install Safari 4.0, it updates WebKit in a manner that breaks Find It! Keep It!. I will fix this but given my current workload, it may take me a few months.

Article published in Mac Tech

June 6th, 2009

Mac Tech just published my article on call stack logging which lets you see which function calls led to my NSLog replacement being invoked. The nice thing is that it works for C, C++ and Objective-C unlike most of the solutions you see elsewhere. The source code should show up on their ftp site some time soon. With few developer magazines surviving (Dr Dobbs webified, BYTE gone), I’m glad Mac developers still have a print magazine to read.

Tetratile update

February 7th, 2009

When you replay a game, I’ve added a panel to let you single step through the moves you made, so that you can better learn how the game works.

I just submitted this update to Apple for inclusion in the AppStore.

Fast enumeration on 10.4

January 29th, 2009

Tomorrow I’m showing some software I wrote to a client, and I don’t want to lug the external Harddrive on which Leopard is installed with me. The laptop still runs 10.4 for testing Find It! Keep It!

The software uses fast enumeration on arrays and sets. Building with the Mac OS 10.5 SDK and with 10.4 as deployment target worked, but running the code on 10.4 failed. The method countByEnumeratingWithState:objects:count: was missing. So I thought I’d add it — I stole its implementation from Cocotron, and added conditional posing for 10.4 systems:


// Stolen from Cocotron

#import <AppKit/AppKit.h>

@interface NSArrayEX : NSArray
@end


@implementation NSArrayEX

+ (void) load
{
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

  OSErr err;
  SInt32 systemVersion;
  if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) == noErr)
    if ((systemVersion & 0xfff0) == 0×1040)
      [self poseAsClass:[NSArray class]];

  [pool release];
}


-(NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)length;
{
  int numObjects=MIN([self count] - state->extra[0], length);
  int i=state->extra[0];
  int j=0;
  state->itemsPtr=stackbuf;

  for(j=0; j<numObjects; j++, i++)
    state->itemsPtr[j]=[self objectAtIndex:i];

  state->extra[0]+=numObjects;

  state->mutationsPtr=(unsigned long *)self;

  return numObjects;
}

@end




@interface NSSetEX : NSSet
@end


@implementation NSSetEX

+ (void) load
{
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

  OSErr err;
  SInt32 systemVersion;
  if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) == noErr)
    if ((systemVersion & 0xfff0) == 0×1040)
      [self poseAsClass:[NSSet class]];

  [pool release];
}



-(NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)length;
{
  int i;
  state->itemsPtr=stackbuf;
  
  state->mutationsPtr=(unsigned long*)self;
  if(!state->state)
    state->state=(unsigned long)[self objectEnumerator];

  id en=(id)state->state;
  
  for(i=0; i<length; i++)
  {
    state->itemsPtr[i]=[en nextObject];
    if(!state->itemsPtr[i])
      return i;
  }

  return i;
  
}

@end

It works surprisingly well. Unfortunately I then discovered that you can only create a 16 bit grey image context on 10.5 Oh well.

(Sorry for the horrible layout — I don’t have the time to dink with Wordpress right now)

setStringValue not clearing the screen ???

January 20th, 2009

I had this strange bug: Setting the string value of a NSTextField wasn’t removing its previous value before drawing the new one. The net result was a mess on the screen, and it was happening randomly.

Of course, I started by blaming Cocoa… I tried using setNeedsDisplay to no avail. Even marking the whole window as needing a refresh didn’t work.

So I stopped, and thought about the randomness. Seems a bit like a race condition… And then I realised my code was running in a sub-thread. Using performSelectorOnMainThread to update the UI once the thread had completed fixed the bug.

Tetratile Video

November 20th, 2008

Tetratile is now available at the Apple Store
I’ve just made a small video of Tetratile in action.

Tetratile

November 20th, 2008

Apple has just approved my iPhone/iPod game Tetratile. It’s a board game which requires you to line four tiles up in a row, a column or a diagonal. You insert pieces from the right or the bottom, so each move changes the configuration of the board. This makes Tetratile quite challenging and addictive.

I think Tetratile will prove to provide many hours of entertainment as each level of difficulty requires an even better understanding of the game.

Here’s a picture of a game in progress:


As you can see the red player is one step away from winning.
The lower bar shows that the red player won the first game, and the blue player won the second.


You can play against the iPhone/iPod, or against a friend.


You play by dragging tiles onto the board. Notice that you can drag from the center of a column or row, as well as from the edge.

Tetratile will be available for a week at an introductory discount of $3 and then it will go up to $5. I hope you like it!

P.A. Semiconductor to focus on the iPhone

June 11th, 2008

The New York Times reports that P.A. Semicondutor will be making systems on a chip for the iPhone platform. So I got this wrong.

Stunning use of Javascript

June 5th, 2008

Slides, a mac like tool in JS. It uses Objective-J, a Objective-C like language. And according to the authors, the framework will be open-sourced.

Two Iphone CPU Architectures?

May 15th, 2008

Intel’s managing director responsible for Germany has apparently revealed that there will be 2 iPhones, one based on an ARM processor and the other on Intel’s Atom processor.

Perhaps this explains this WWDC picture:

(image courtesy of computer world)