381Zero-Padding in Objective-C

The age-old problem. Files, that are stored with padded zeros 000, 001, 002, 003 – and a counter that doesn’t have this zero-padding. There are probably myriad solution to that problem, here’s my take:

Create a temporary string consisting of a minimum of 3 characters length.

NSString *tempZeros = [NSString stringWithFormat:@"00%i", i];

Get the last 3 characters, shave off the rest.

NSString *zeroPaddedIndex = [tempZeros substringFromIndex:[tempZeros length] - 3];

No if’s, no but’s, no clauses.

Update: Of course, there’s always a better way. 452

379Never use a beta SDK for active development

As seen in iPhone SDK 3.2 beta 2 and the “A signed resource has been added, modified, or deleted.” error message.

Solution? Switch back to iPhone SDK 3.1.3 with XCode 3.2.1

Apparently several different versions of XCode (and the Developer Folder) can happily coexist. Just rename one DeveloperBeta or something like that…

376Variable length of accuracy of float in NSString

float f = 1.23456;
 
NSLog(@"%.2f", f);
NSLog(@"%.0f", f);
NSLog(@"%.0f", f);

1.23
1
1.23456

374Delay method execution, part II

[NSTimer scheduledTimerWithTimeInterval:1.0 
target:self selector: @selector(methodName:)  
userInfo:nil repeats:NO];

Alternative to Part I [35], has the possibility of repetetive calls.

367Missing constants in RubyCocoa for Snow Leopard

Not sure if anyone except me will need this information again.

Situation: A legacy RubyCocoa Application that runs fine in OSX 10.5, but refuses to compile in 10.6. RubyCocoa is working, only access to constants seems to be problematic.

So far the following workarounds:

<del datetime="2010-02-02T06:57:40+00:00">OSX::KCGScreenSaverWindowLevel</del> ➯➤➲ OSX::NSScreenSaverWindowLevel

Bug Report and Workaround about inproper mapped constants in Bridgesupport on Snow Leopard
http://lists.macosforge.org/pipermail/macruby-devel/2009-October.txt

Notes
Structs in Ruby