How to Create an Xcode 4.0-style Window-based Application in Xcode 4.2

I’ve decided to get up to speed on iOS programming and, to help me with that, I bought Aaron Hillegass’s iOS Programming: The Big Nerd Ranch Guid 2nd edition. I’ve listened to Aaron on podcasts and have heard that his training method is fantastic. The book does seem to be unusually well written for a tech book but the problem I immediately ran into is that it was written for Xcode 4.0 and iOS 4.3 SDK. I have Lion with Xcode 4.2 and iOS 5 SDK. That’s part of the adventure of discovery and change in tech but unfortunately Apple removed the project type that Hillegass’s examples are based on which is a major stumbling block.

Hillegass uses the “Window-based Application” template for iOS as the basis for all of his projects. That template no longer exists in Xcode. The closest thing in Xcode 4.2 is “Empty Application”. However, that’s not quite the same thing because the now-defunct “Window-based Application” template generated a main window XIB view wired to generated controller but the “Empty Application” has no XIB. In order to make any sense out of the book, you have to create the XIB and wire it up yourself. This is no big deal to anybody with a little experience but to a newb like me, it took a bit of wandering in the wilderness at the Big Nerd Ranch forums to figure out how to manually get the project into the state that the exercises in the book will work.

How to Convert a new “Empty Application” into a “Window-based Application”

Start by creating a new iOS Application project using the “Empty Application” project. This will create a very similar project to the “Window-based Application” project described in iOS Programming 2/e with just a few differences:

  1. The main controller class that gets generated is “AppDelegate” rather than “<project-name>AppDelegate”. The
  2. There is no XIB view.
  3. The window property of AppDelegate doesn’t have the IBOutlet macro to make it visible to the Interface Builder tooling.
    1. Prepare the controller to talk to the Interface Builder tooling

    In the controller class interface definition of the we need to add the IBOutlet macro so that the tooling will recognize the controller. In your controller header file, AppDelegate.h, the line to modify begins with @property and ends with *window. Add IBOutlet in front of the UIWindow type as shown below.

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;


Save this change.

Update the didFinishLaunchingWithOptions: method

The auto-generated first line of code in the didFinishLaunchingWithOptions: method of AppDelegate.m prevents message routing from working properly. Comment it out as below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    //self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;

Save this change.

Create the XIB file

Right-click on the folder containing your AppDelegate files and choose “Add File”. Select “Window” from the iOS User Interface group. Choose the appropriate device family—for the initial Quiz project that is iPhone. The default file name is Window.xib which works fine or you can name it MainWindow.xib to make it just like in the book.

OS X 10.7 (Lion)-2011-11-23-11-18-56

Change the Class of the XIB file’s owner to UIApplication

Select Window.xib in the Navigator. Select the “File’s Owner” cube in the objects pane just left of the layout canvas and change the Class in the properties pane to UIApplication.

OS X 10.7 (Lion)-2011-11-23-11-34-47


Add an object for the controller

Filter the tool pallet on the bottom right to “Objects and Controllers” and drag and drop an Object from the toolbox onto the object pane.

OS X 10.7 (Lion)-2011-11-23-11-37-52

Set the class of the controller object

In the properties window, change the class to controller that was generated for your project by the template. That should be AppDelegate. The Object will automatically be renamed with a space added into the Pascal casing. (You can override this by putting something into the Label field of the Identity pane.)

OS X 10.7 (Lion)-2011-11-23-11-45-00

Route the XIB delegate to the controller

Now we want to wire up the MVC message routing for the view. Select the “File’s Owner” cube in the object pane and control+drag the delegate outlet to the App Delegate object.

OS X 10.7 (Lion)-2011-11-23-12-00-15


Route the controller object’s window outlet to the window object

Next perform a similar ctrl+drag of the window outlet from the App Delegate object to the Window object.

OS X 10.7 (Lion)-2011-11-23-12-01-08

All done

Now our Empty Application project is set up just like a Window-based Application as described in iOS Programming 2nd Edition. The file names may be a bit different but that should have no practical  effect. The AppDelegate inherits from UIResponder <UIApplicationDelegate> rather than NSObject<UIApplicationDelegate>. This doesn’t seem to be a problem, either.

Now that I have figured out how to create an wire up a main window XIB file, everything seems to work great as I follow along in the book.

“Bins” for Windows 7 is *Bleeping* Awesome

I have a problem. I can’t fit all the icons I would like on my taskbar because I end up with 2 rows of icons when I’m undocked. There are ugly-workarounds like putting the taskbar into small (read ugly) icon mode or waste space with a double-high taskbar. I have to pick my most favoritest apps to pin on the taskbar and put the rest that I used slightly less frequently into the start menu ghetto. I like that icons don’t jump around on me on the Windows 7 taskbar but I always wished it had some smooth icon scaling like in OS X.

I just found something better, though. It’s called “Bins” and it allows you to group icons on the taskbar together just like folders in iOS or Lion’s “Launch Pad”.


It works exactly like you would want. You can choose one of the apps in a bin as the default icon. The default app is the one that gets launched if you just click the "bin" or middle-click the bin to launch a new instance. To launch any other app in the bin you roll over and click it. The rollover is super-fast and smooth. Aero peek still works. Jump-list gestures are gone but they do work by right-clicking on an icon in a bin.


As a bonus, Bins also lets me pin the recycle bin to the task bar just like in OS X, although I pinned it to the leftmost position. I can just drag stuff onto that taskbar icon to trash them and it never gets covered up. You can also pin Explorer shortcuts to the Explorer bin to get one-click access to your favorite folders.


I was easily able to fit everything on my taskbar that was previously exiled to the Start Menu ghetto.

This little app is awesome. It’s well worth the $5 asking price and, by the way, Microsoft should just acquire this company and incorporate the concept into Windows 8. Get it at

via lifehacker


After about 2 weeks with Bins, I uninstalled the product. While it does make the taskbar much more compact and is great for launching apps, it is not as good for task switching. What I found is that it requires quite a bit more manual dexterity to switch windows. I tend to have a lot of apps open simultaneously, so the task switching turned out to be a deal killer for me. Scott Hanselman has named Bins one of his 5 absolutely essential utilities, though.

How to Infuriate Your Custom Software Client in Three Easy Steps

locked-mysqlMy wife just asked me to take a peek at database application that her organization had custom developed using a local Ghanaian consultant, “Andy”. They have some issues with excruciatingly slow reports and an arduous data cleaning workflow that involves exporting to Excel to find errors and then picking through screens to fix them in the software. The application is a WAMP stack web app and running standalone on a single analyst’s Windows desktop and the data set is pretty small. They need a much more efficient batch data access mechanism and they need to be able to run ad-hoc queries from time-to-time without signing a new support agreement to have additional features baked into the system. It is a custom-built system that was bought and paid for over a year ago.

My idea was to set up MySQL Workbench so that they could do some back-end data cleanup in a spreadsheet-style view of the data tables. This would also allow them to issue ad-hoc SQL queries to so that they can respond quickly to requests to slice-n-dice their data in new and interesting ways. Unfortunately, it turned out to be not so easy because Andy has done everything in his power to lock his clients out of the data system they paid him to develop.

#1: Gratuitously Encrypt the Source Code

Despite having been contractually obligated to provide complete source code, Andy encrypted the entire application with SourceGuardian. This is deeply uncool to do to a pure custom software consulting client and also an explicit breech of Andy’s terms of reference. Furthermore, the application is 99% Pear PHP modules. It’s just a login to an Access-like switchboard with what appears to be one data entry screen per table and one export-to-CSV per table. Most of what is encrypted is Pear modules and just a handful of PHP scripts for the data entry screens.

#2: Hold Your Client’s Data and Configuration Hostage

Andy the Consultant set up the WAMP stack on the Windows box and installed the application. He did not give anyone the root password for MySQL. Among the pile of encrypted PHP is the uselessly named config.php which probably has the database connection string in it and if not there in one of its siblings. There’s no way to know a priori if Andy has created an account for the application or if his application is using the root account without resetting the root account experimentally and seeing if it breaks the app.

#3: Refuse Access to Both Source Code and Data

My wife called Andy to get the MySQL root password and he refused, citing professional IT ethics and a technicality of the reporting structure of his contractual agreement: to wit, my wife is the project deputy director but Andy is a second-tier subcontractor so his agreement is technically with a subcontractor working for my wife’s company and hence it is unethical to release any information directly to the management of the company overseeing said subcontractor. What?!

This is egregiously forced lock-in. The data and source code are hostage to the whim of the development consultant who has made himself irreplaceable as long as the data has value.


There is an effort underway to apply some Ghanaian social pressure to Andy as well as the implied threat that he is risking freezing himself out of the USAID and foreign donor market in general. That said, as an owner of a software company that does commercial custom development, I myself am deeply offended. Even if Andy had an agreement where his entire work product remained proprietary there is just no circumstance I can envision in which it is ethical to lock up a customer’s data.

In any case, this data isn’t going to stay locked up. If Andy doesn’t cough up the MySQL password, I’m just going to capture it out of the raw packet frames using RawCap and open the resulting capture into WireShark to take advantage of the built-in MySQL protocol filters.

Don’t Let this Happen to You

Word to the wise. When having custom software work done—especially in an emerging market context—you need some Independent Verification and Validation that you got what you paid for because you have very little leverage over your consultant after he has been paid.

Windows 8 Metro + Desktop: Give it a Chance

When I first heard about the idea of the Metro-style UI from Windows Phone 7 being incorporated into Windows as a wholesale replacement for the traditional start menu, I was extremely skeptical that it would work on a professional desktop. Things like the Ubuntu Unity and Gnome 3 environment are horrible. I don’t get the point of the Launchpad in Lion because it’s just superfluous.  The concept of putting the Metro phone UI in to replace the start menu seemed just crazy to me.

I have downloaded the developer preview of Windows 8. After I booted up for the first time, it was disorienting for a few minutes. It reminds me of when I booted Windows 95 for the first time and was thinking where’s progman and this explorer view is weird, can I get fileman back?

But after a getting my bearings, I realize that I can do everything I could before with about the same effort and very similar behaviors but there is this cool news stuff in there.

The Metro Start screen completely replaces the classical Start Menu from Windows 95, but even though it takes up the entire screen and looks very different with the tiles, it can do all of the stuff the Win7 Start Menu did.

First of all win + type stuff initiates a search just like in Windows Vista and 7, the UI is different but the functionality is the same. Next, any time you install a classic or what Steven Sinofsky called a “professional app” in his keynote, the icon is added to your Start screen. It is also available by browsing an alphabetical list of apps which you can get to from the “Seach Charm” which you access by hovering your mouse on the bottom-left where the Windows pearl is on Win7 or by using a swipe from the right edge touch gestures. Right-clicking on any tile that links to an applications that supports a desktop mode reveals an option to pin it to the desktop taskbar.

Alt+Tab and Win+Tab flip through applications pretty much as you would expect. The Win+Tab Aero Carousel effect is gone and you get the Metro swipe-from-left app switching where one of the screens is the desktop. Win+Tab is particularly useful if you have an app docked on the side of your screen and want to flip between the desktop and another Metro app.

I think this description sounds more convoluted than it is. The point is that everything works surprisingly well considering this is an alpha quality build. All of the old keyboard shortcuts and mouse behaviors work the same way.

The idea of having Metro apps docked on the side while using most of the screen for the desktop is very cool. the Metro demo apps are beautiful. A great example is the built-in RSS reader. It is just gorgeous, for consuming photo blogs. Any blog which publishes its entire content into the feed gets a really nice columnar newspaper-style layout. I’m convinced the Metro stuff is worthwhile and that Microsoft will successfully blend the classical Desktop and the Metro UI into a coherent and usable whole, although I suspect that phones and ARM-based tablets will not have the Desktop.

On with the screen shots.

Metro News App Columnar Text View


Metro News App Displaying a Photo Blog



Metro News Docked with Desktop


SUA Deprecated in Windows 8

The POSIX subsystem in Windows is headed for a slow death march, again. Not many people realize that Windows NT had a POSIX subsystem from the beginning which was enriched along the way to run a fork of OpenBSD called Interix. Originally the POSIX subsystem was bundled with Windows NT 3.1 and was a barely useful POSIX.1 environment to meet DoD purchasing requirements. Later, it was removed from the Windows core distribution, re-implemented by an ISV and called OpenNT and then Interix. Interix was acquired by Microsoft and sold for a while before being distributed free of charge. Later it was bundled with Services for UNIX 3.0 and 3.5 before being re-integrated into the Windows distribution as the Subsystem for UNIX-based Applications (SUA). At one time Interix actually ran Hotmail during the migration from a FreeBSD to NT backend.

After passing back to the Windows team and being rebranded SUA, Interix languished. The original developers scattered to other projects like Monad/PowerShell, left Microsoft or were never hired by Microsoft when it acquired the technology in the first place. Interix is maintained by a very small team at Microsoft India and these guys are focused primarily on just keeping it working through kernel updates. In practice, the quality of the product has been in decline. At one point, for example, it shipped with most of the .so shared libraries corrupt so that nothing that linked to those libraries would run. The toolkit that makes SUA useful lags many, many months behind the release of a new version of Windows and Microsoft required “premium” client SKUs (ultimate or enterprise) or server SKUs to access the technology which greatly limited its distribution. It is generally as unloved by the powers that be as anything could be, except perhaps IronPython and IronRuby which have already been killed.

The Windows 8 M3 developer preview shows that the other shoe has dropped:

Subsystem for UNIX-based Applications [DEPRECATED]

Subsystem for UNIX-based Applications (SUA) is a source-compatibility subsystem for compiling and running custom UNIX-based applications and scripts on a computer running Windows operating system. WARNING: SUA is deprecated starting with this release and will be completely removed from the next release. You should begin planning now to employ alternate methods for any applications, code, or usage that depends on this feature.


One obvious reason to deprecate SUA is that loading the extra subsystem makes Windows take a noticeably longer time to boot. The architecture is very much at odds with the instant boot goals of Windows 8.

There have been a number of developments over the last few years that makes Interix less compelling. Things like fast-CGI on IIS and an official PHP port from Zend, lots of dynamic languages with native Windows runtimes, mySQL and PostgreSQL for WIndows, C libraries like pthreads for win32 and msys which have made Interix less necessary. For perl-heads there is even Strawberry Perl which is supposed to be a lot more CPAN friendly than ActiveState perl. I think Hyper-V and PowerShell are the real strategic replacements for SUA, though. PowerShell integrates with COM and WMI and fits the object nature of Windows better than any POSIX shell could. Hyper-V lets you actually run your UNIX app on Windows on a supported Linux platform which I’m sure smells much less MacGuyver to CIOs than this weird Interix POSIX on Windows thing that nobody ever heard of.

From the time that Hyper-V officially supported RHEL with hast enlightened drivers and Jeffrey Snover decided that the new shell and automation for Windows would be based on .NET and pivoted to build Monad/PowerShell rather than putting KSH on every Windows machine, Interix’s days were numbered. Now it’s official, Interix will be gone from the world about 11 years when Windows 8 reaches end-of-life but if you are smart you will jump ship now because this product will have the minimum life support staff imaginable.

A Better Telnet for Windows

console telnet in semi-transparent console2 powershell sessionThere’s no really nice way to say it: the telnet client in Windows is a little strange at best. I mostly use telnet to debug text-based TCP services. The Microsoft telnet implementation isn’t very good for this. I have used a PowerShell script to fill the gap by piping stdin and stdout to the console but sometimes I actually want telnet. I don’t want to go on a tirade about its problems here but telnet doesn’t work the way I want. What I really want is the telnet from GNU inetutils but compiled for Win32 with no extra runtime requirements. I don’t want to have to install Cygwin or MSys or SUA in order to get telnet.

I looked into this a little bit and it seems like inetutils has a lot of dependencies that make it hard to compile to run directly on Win32 without any POSIX layer. I also found an abandoned project on SourceForge called Console Telnet for Win32 which is under GPL, supports ANSI color codes and seems to have quite good VT100 emulation. The last code drop is from October 2000 and was originally written for old versions of Visual C++ or Borland C++, but it looked promising.

I spent a little time fixing up headers and a few functions here and there to get the code to compile with Visual Studio 2010. It works and it works pretty much like the GNU inetutils version of telnet except that it is annoyingly chatty about printing out info about its configuration on every connection so I put the chatty stuff behind an #IFDEF CHATTY and compiled without that CHATTY symbol defined which pretty much gave me what I wanted. It works by piping stdin/stdout to the TCP connection and doesn’t do any crazy erasing of your entire console scrollback buffer the way that Microsoft’s telnet does. It also doesn’t crash Console2.

I haven’t done extensive testing but everything seems to be working on my computer. I watched as much of Star Wars as I could stand at (“telnet”) and I’ve passed a bunch of HTML GET queries and responses through it.

Get the Code and Binary

Here’s the source code and compiled binary. You need to have telnet.exe, telnet.cfg and telnet.ini together in a directory for it to run correctly.

Let’s Play Spot the Scam

IMG_0235I just received an SMS message on my phone from +37240017000:

call for free your number has been selcted [sic] to win 50000$ call us 0037240017000 now this is your chance

Based on the country code that SMS originated from Estonia. I don’t know anybody from Lithuania and my phone is on the Vodafone network in Ghana. Occam’s Razor says this is most likely a scam rather than my newfound Estonian friends wanting to send me $50,000.

I don’t know exactly how this scam works. Is calling the number enough to somehow have charges placed on my phone? I don’t know. My bet is that it is a flavor of 419 scam where I have to give these nice people my bank wire details and then rather than wire transferring money into my account the wire money out.

Remember kids, if someone has your account number and routing code, they can initiate the transfer in either direction.

Also, you should always avoid replying to SMS messages for “contests”. These can be set up to charge you a fee for the SMS just like you can text the Red Cross or NPR to make a donation.

For people with more time than I have, there is a scam baiting community which aims to make the 419 scam unprofitable for the fraudsters. Its pretty entertaining to read.

Hide VMWare Virtual Network Interfaces from Windows Firewall and Network and Sharing Center

VMWare Workstation creates two virtual network adapters by default. One is the host-only network and the other is for NAT routing. You can add several more to suit your needs for more complex scenarios.

The problem is that these networks cause Windows 7 to think it is attached to a public “unidentified network” which has the side-effect of disabling network and printer sharing. You will experience the same problem with Windows 7 Virtual PC if you create virtual loopback device adapters and the same problem occurs with VirtualBox.

The solution is to mark the virtual network adapters as *NdisDeviceType=1 in the registry:


The type of the device. The default value is zero, which indicates a standard networking device that connects to a network. Set *NdisDeviceType to NDIS_DEVICE_TYPE_ENDPOINT (1) if this device is an endpoint device and is not a true network interface that connects to a network. For example, you must specify NDIS_DEVICE_TYPE_ENDPOINT for devices such as smart phones that use a networking infrastructure to communicate to the local computer system but do not provide connectivity to an external network.

Note  Windows Vista automatically identifies and monitors the networks a computer connects to. If the NDIS_DEVICE_TYPE_ENDPOINT flag is set, the device is an endpoint device and is not a connection to a true external network. Consequently, Windows ignores the endpoint device when it identifies networks. The Network Awareness APIs indicate that the device does not connect the computer to a network. For end users in this situation, the Network and Sharing Center and the network icon in the notification area do not show the NDIS endpoint device as connected. However, the connection is shown in the Network Connections Folder.

As far as I’m concerned this is just a bug in both VirtualBox and VMware Workstation. They should be marking their virtual network devices as *NdisDeviceType=1 for compatibility with NT 6.x –based operating systems.

Until they do that, I cobbled together a little powershell script to find any NICs created by VMWare and mark them as virtual. The setting takes affect after a reboot.

# tell windows that VMWare Network Adapters
# is not a true network interface that connects to a network
# see
echo "Marking VMWare Virtual Ethernet Adapters as virtual.`r`n"
cd 'HKLM:\system\CurrentControlSet\control\class\{4D36E972-E325-11CE-BFC1-08002BE10318}'
ls ???? | where { ($_ | get-itemproperty).DriverDesc `
-like 'VMware Virtual Ethernet Adapter *' } | `
% { $_ | new-itemproperty -name '*NdisDeviceType' -PropertyType dword -value 1 } | `
% { "`"" + ($_ | get-itemproperty).DriverDesc + "`" -> *NdisDeviceType=1" } 
echo "`r`nReboot to apply changes."

Mount SkyDrive Natively in Windows

Microsoft SkyDrive is a free 25GB online storage locker available to anyone with a Live ID. Microsoft just gave it a fresh new web interface but has never provided a way to access it natively from the Windows Shell.

On the bright side, SkyDrive is implemented on WebDav over SSL which is an open standard and one that is incorporated into Windows Vista and later. (You could map a drive to a WebDAV location in XP too but not over HTTPS.)

The trick is that the SkyDrive DAV URLs are obscure and not easily discoverable but I found a cool little command-line utility on codeplex which spits out the URLs to each of your root-level DAV shares in SkyDrive.



Use these URLs with net use or “map a network drive” in Windows Explorer and you have access to skydrive contents via the Windows Shell or a command-line.


It seems like this should also work in OS X but the Finder keeps giving me an error bonk that it can’t contact the server. I’m not sure what the problem is there.

Cool PowerShell Script Replicates Telnet

Lee Holmes has a cool script to reproduce telnet-like functionality via the TcpClient object in PowerShell.

## Connect-Computer.ps1 
## Interact with a service on a remote TCP port 
    [string] $remoteHost = "localhost", 
    [int] $port = 23

    ## Open the socket, and connect to the computer on the specified port 
    write-host "Connecting to $remoteHost on port $port" 
    $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) 
    if($socket -eq $null) { return; } 

    $stream = $socket.GetStream() 
    $writer = new-object System.IO.StreamWriter($stream) 

    $buffer = new-object System.Byte[] 1024 
    $encoding = new-object System.Text.AsciiEncoding 

       ## Allow data to buffer for a bit 
       start-sleep -m 500 

       ## Read all the data available from the stream, writing it to the 
       ## screen when done. 
          $read = $stream.Read($buffer, 0, 1024)    
          write-host -n ($encoding.GetString($buffer, 0, $read))  

       ## Read the user's command, quitting if they hit ^D 
       $command = read-host 
       ## Write their command to the remote host      
    ## Close the streams 

This solves the problem of telnet.exe crashing conhost.exe when using Console2.


I tweaked Lee’s code to use try/finally which obviates the need for a special escape sequence to clean up the TCP resources.

%d bloggers like this: