Pi Brain 1.1 Changes

When the original OS 3.0 SDK came out, the behavior of the UITextView was different. The original Pi Brain was compiled as target OS 2.2.1. This source did not compile in 3.0 without having to make some modifications. The UIButton method to change the size of the text was changed.

   UIButton *item;

   [[item titleLabel] setFont: systemOfFontSize: 36.0]];  // OS 3.0
   [item setFont: [UIFont systemOfFontSize: 36.0]];  // OS.2.2.1
   

The UITextView contains the digits display. The scrolling is set so that the end of the text is always displayed. I was surprised that under 3.0, the scrolling not longer worked correctly as it did in 2.2.1. I also remembered how I struggled to get the 2.2.1 code working correctly. It turns out that the text scrolling in 3.0 it works much better, you only need to set it up once:

   UITextView *textArea;
   [textArea setContentOffset: CGPoint];
   [textArea becomeFirstResponder];   // OS 3.0
   [textArea scrollRangeToVisible:NSMakeRange([textArea.text length], 0)];
   

Pi Brain changes the size of the textArea when switching from Test to Learn mode, and is adding to the text for every key press. Under 2.2.1, this change to the text length of the window size confused the scrolling. In order to make things work, it was necessary to call scrollRangeToVisible every time the window size or text length changed. Calling becomeFirstResponder does not work in 2.2.1. For 3.0, the UITextView knows how to handle a window or text length change automatically.

The OS can be found at run-time as follows:

   NSString *os_version = [[UIDevice currentDevice] systemVersion];
   

I check the first character in the string for '3' to determine what should be done at run-time. I probably could have figured out what to do back when I first worked on upgrading to 3.0, but at the time, I did not have a Revision Control System setup at Home. I did make copies of the source for each release, but nothing beats the ease of comparing then using a RCS. I ended up using Subversion, which Xcode has direct access to. I used Subversion with Xcode in my last job, but didn't set it up at home because I wasn't sure how much time it would take. Turns out Apple has most of the tools built in on the Mac, so configuration was a snap.

Other changes for 1.1

I am using SQLite to store the 'scores'. Since I already did something similar for 'Coin Brain' adding this new feature was easy. I reused many of the ViewControlers for the scoring, so if you compare the two apps, you will see similarities. I updated some of the tab Icons, and changed the key click sound (from what was used in Pi Brain3) to the Select.caf from the sample GLPaint. The sound must be short to keep up with the fast fingers of users. The size of the file submitted to Apple when from 88 KB to 440 KB, mainly because of the two new libraries used for Audio and SQL, and the new code.

Now that Pi Brain 1.1 is available, 'Pi Brain3' has been removed.