January 2008 Archives
One of the new features of Objective-C 2.0 included with Leopard is fast enumeration. This is essentially new syntax to iterate collections using new for...in syntax:
NSArray *array = [NSArray arrayWithObjects:
@"One", @"Two", @"Three", @"Four", nil];
for (NSString *element in array) {
NSLog(@"element: %@", element);
}
The best part about this is that you can use this on your own collection classes by implementing the NSFastEnumeration protocol. This is quite similar to Ruby’s Enumerable module. You can loop through integers really easily in Ruby since Ruby’s Range class implements Enumerable:
#!/usr/bin/env ruby
(1..5).each { |i| puts i }
I thought this would be pretty cool to add to Objective-C, but it turned out to be more difficult than I thought.
The latest script I added to the dld-tools project (in my public Mercurial repositories) is called fswatch. The script, as of this writing, is available here. Click on “raw” to get a file you can save and run. Check the repository for newer updates.
fswatch is a Ruby script that uses the built-in RubyCocoa bridge to access the new File System Events (FSEvents) framework added in Leopard and watches for filesystem modifications while a command is run. Since FSEvents can efficiently watch a directory hierarchy, you can see what files a command touches or spews anywhere on the filesystem. One use case would be to see what a make install actually does. Here’s an example installing the GNU Hello program:
% sudo fswatch -o /tmp/hello-install.txt make install
% cat /tmp/hello-install.txt
/
tmp
/private/tmp/
.
hello-install.txt
/usr/local/bin/
.
hello
/usr/local/share/
.
info
/usr/local/share/info/
.
..
dir
hello.info
/usr/local/share/man/man1/
.
hello.1
I’ve carved out some space on my server for public Mercurial repositories. You can browse them at:
So far, there’s only two projects, but I’ll probably be adding more as I convert my Subversion repositories to Mercurial. I may even move my Google Code project to my own server under Mercurial.
While evaluating distributed version control systems (DVCSs), one of the initial challenges was getting Git, Mercurial, and Bazaar installed on Mac OS X 10.5, Leopard. At first I tried MacPorts, but that really gave me a headache. Read on for how I installed them.
