Thursday, February 25, 2010

SVN: externals - Key to sharing libraries


As any developer knows, it’s very useful to reuse code. If you have written some code that performs a useful function, it makes sense to modularize it so it can be easily reused in other projects.

If all your development is occurring on one machine, then sharing those modules between projects can be fairly simple. In my case, I have a custom Libs/ directory where I put common source code for various features, such as my web view controller, my RadioKit audio streaming engine, autoscroll label, etc. When I want to use any of those modules in a new project, I directly reference this common Libs/ directory. That way, if I later fix a bug in a module, I don’t have to find everywhere I’ve included the code. All the projects reference the same source and the change is easily reflected across all my projects.

Now, add in the complexity that you don’t have all the modules in a common directory on one computer. How can you still easily share the code across projects and ensure they automatically include new changes when they are made? SVN!

SVN (or Subversion) is a source code version control system. There are plenty of alternatives to SVN, and they all have their merits, but since SVN comes with the Mac, it’s an easy option to use.

I’m not going to get into the details of setting up SVN to use with XCode. That’s been covered well in other places. What I do want to talk about is a handy feature of SVN which makes sharing pieces of other SVN projects in a single project. The feature is called “externals”.

Suppose you have an iPhone XCode project that is being managed via SVN. Now, suppose you want this project to include 2 additional modules, and the source code for each module is hosted on a different SVN repository. You could manually check-out each of the pieces which will make up the project, but now suppose someone else wants to also work on this project. You would need to tell them where to get the extra modules and they would have to manually fetch (or check-out) the code from the other two repositories and put it in the proper place.

With SVN externals, you avoid all that manual work. You can easily define in your project where all the external pieces are coming from. These externals definitions get saved as part of your SVN project, so if someone else checks out the same project, SVN will also automatically check out the necessary pieces that were hosted on the other external SVN repositories. And, when you then open the project in XCode, XCode will automatically track the changes to the whole project, even the modules that were retrieved from the external repositories.

The externals feature makes it a whole lot easier to manage pieces from multiple SVN repositories, all while making them appear to be self-contained in the current project.

There’s a decent description of the syntax for using “externals” here. Also, most graphical SVN tools (such as Cornerstone or Versions) have support for defining externals. Unfortunately, the XCode SVN interface does not provide a method for defining externals. You need to either use the command-line or a GUI tool to initially set them up.

NOTE: since the externals are a property of a project, in order to define them you must first check-out the project which will use them. I didn’t understand this detail at first and spent quite a bit of time trying to figure out why the externals option was read-only when using the GUI tools and looking at the repository. If you run into that problem, check-out the project first, and then set the externals property on the working directory, not the repository.


WFMU 2.0 now available on iTunes

Stormy Productions has developed the latest iPhone app for WFMU and it is now available as a free download from iTunes. WFMU-FM is a listener-supported, non-commercial radio station broadcasting at 91.1 Mhz FM in Jersey City, NJ, right across the Hudson from lower Manhattan. It is currently the longest running freeform radio station in the United States.

The new 2.0 app has many new features including:

* Support for listening to several live audio streams including Ichiban Rock ‘n’ Soul, UbuWeb Radio, and Do or DIY
* On Demand access to show archives and podasts, including interactive playlists for some shows
* Bookmarking song favorites and searching for them on iTunes
* View WFMU’s Twitter feed, station news, blog feed, upcoming specials, and current schedule information
* Rewinding live radio
* Support for background play of all audio (including on demand content)

PastedGraphic.3EmYJYut4OHy.jpg PastedGraphic1.v8XjjMwd614b.jpg

Wednesday, February 17, 2010

Artificial Life 2.0 now available

Artificial Life 2.0 iPhone app is now available on iTunes.

Screenshot_6.rsk6Ge0xLUpW.jpg

Artificial Life is a simulation of the evolution of behavior of microorganisms. This newest update adds a new mode of play called Survival Mode. In this mode, you create the rules of behavior for one protozoa and see how long it will survival vs. a random population.

You can read more detail about this app here.

Here’s a short video demonstrating some of the features:

Thursday, February 11, 2010

DevTip: Improving responsiveness of tab-based view controllers

I recently noticed a behavior difference between two different apps I had developed which both used UITabBarControllers. In one app, pressing each tab would immediately display the associated view controller’s views. In the other app, the first time a different tab was pressed, there would be a noticeable delay before the view controller’s view was displayed. After one time pressing each tab, however, then the response time was immediate for each tab.

When it comes to view controllers created from NIB files, the iPhone conserves memory by automatically loading and unloading them when necessary. So, when your app first launches, even if your view controllers are assigned to IBOutlet variables, their underlying views have not yet been created unless there is an immediate need for them.

In the case of my two different apps, in the one that had all its tabs being immediately responsive, it turns out I was doing some preliminary access to the view controllers views in my applicationDidFinishLaunching: method. Simply accessing the underlying view of the view controller will cause it to be loaded from it’s NIB file.

The benefit of doing this is each view controller will be initially loaded into memory when the app launches. This in turn will give better responsiveness to the view controllers being displayed when you initially press a tab.

The drawback is a slightly longer startup time for the app and you are now using more memory. Also, there is no guarantee that each of the view controllers will remain in memory. The iPhone OS may decide to unload one or more of them if memory conditions warrant it. But, if you have fairly complex views in a view controller and want to increase the likelihood the view will be immediately ready for display when a tab is pressed, using this technique will help.

All content copyright © 2009  Brian Stormont, unless otherwise noted.   All rights reserved.