Coding on Apple is still a love/hate relationship

So, it’s been almost two years since I posted anything here, and it’s just over two years (almost to the day), since I last had a good whinge about XCode. It has only been laziness that has kept me from spewing much guts here about all kinds of annoyances.

So, I’ve been learning Swift for the past year, and whilst it was long overdue, it’s only the language part of the equation. The Cocoa API is still a nasty piece of work; give me the .NET Framework and C# ANY DAY (except if that means I have to use Windows at home; sorry, but I can use it at work writing web services and such like, but I’m not letting that operating system near my computer at home).

So, here’s what drove me mad about XCode/Swift/Cocoa today:

I used to have a drag/drop connection between a combobox and a class to handle the selection change event. That worked fine, however, when I modified it to also handle updating something as the user typed each letter in the combobox, the handling of selection changes failed. You can only handle one or the other when doing the drag/drop connection crap between the combobox and the IBAction.

So, I found a delegate method, which means that I modified the relevant view controller to implement the NSComboBoxDelegate protocol so that it suddenly receives all of the methods in that protocol, whether I implement them or not; the ones I care to implement actually do get called, and the others are ignored. This seems strange to a .NET programmer, and takes a bit of getting used to, but it can also be very powerful (and a time saver in some cases).

This delegate method is the comboBoxSelectionDidChange notification. Being a “did change” event you’d think that it would only call the method when I have actually finished selecting an item from the drop-down list portion of the combobox. You would be mistaken. Past tense apparently isn’t past tense in Cocoa.

Only one problem: if I use “combo.stringValue” inside that method it still returns the previous value in the text part of the combobox. If I want to get the text of the item that the user selected, I’ve got to do this:

dateCombo.itemObjectValueAtIndex(dateCombo.indexOfSelectedItem) as! String

I do not have the words to describe my disappointment.

Come on Apple, the Cocoa framework needs a decent upgrade.


Read More

Self Flagellation with Objective-C and XCode

This post is called Self Flagellation with Objective-C and XCode because I think that is an apt description of what I’m doing. In case you don’t know what flagellation is, this wikipedia article will provide the full story, but suffice it to say that it comes from Latin and means whipping, and that’s exactly what I’m doing to myself every time I try to use XCode.

I should probably number my grievances because there are probably going to be many, and they’re not in any particular order. I should also point out that it’s early days for me with XCode, but after buying several ebooks on Objective-C and Mac/iOS development, and reading two so far and doing all the exercises therein, I’ve had more than just a cursory glance at XCode, and I feel as though I’ve given it quite some time for it to prove its worth before giving up and curling up into a ball, crying like a baby (which is an appealing prospect at the moment!).

  1. XCode is full of annoying control-dragging of things to other things, for example, simply in order to wire up an event for a button or an outlet for same if you want to be able to talk to said button programmatically.


  2. Clicking on a file to work on it overlaps the previous file you had in the main editor area in the middle. If you double-click on the file, it opens in an entirely separate window, not in a tab as one might expect of any normal IDE. You can open files in a new tab, providing you open the new tab first, then click on the other file you want to open in that new tab. There is no right-clicking on said file to open in a new tab, that would be too useful!


  3. This is more to do with Objective-C than XCode but all classes are really split across two files, the header file (.h) and the implementation file (.m). As someone who is used to storing everything for one class in a whatever.cs file in my day job, having to toggle between .h and .m at home is a major pain. The logic (as far as I can tell) is that the .h describes the public interface that other objects get to see, and you could theoretically let the world see these .h files without giving away your trade secrets, which are kept safely hidden in the .m files. Maybe this makes sense to people who are in the business of writing third-party libraries or open source developers, but I don’t care about all that; I simply want to have one god-damned file for the lot, but it seems it’s a very bad idea to try to do this anyway. Having to switch between these two all the time is just a major pain in the you-know-what!


  4. As someone how was brought up with Windows 95 to Windows XP then various Linux distributions for the roughly five years to December 2012, I’ve come to consider certain keys on my keyboard as being “normal”. For example, pressing the Home button jumps the cursor to be beginning of the line. Not so on a Mac, it goes to the beginning of the entire document! How many times do you think somebody might want to start typing at the beginning of the document? No much, hey! Anyway, XCode does let you map the Home key to move to the beginning of the line (unlike the rest of Mac OS X, unfortunately), however it does exactly what it says, moves to the beginning of the entire line, and not to the first actual character of code after the white space used to indent your code properly. This is just another one of those things that makes me wonder whether anybody at Apple actually uses XCode, and that perhaps they’ve got some secret in-house IDE they keep to themselves because when I press the Home key, I expect it to go to the beginning of the “if” statement or whatever it is. I’m sure any other normal developer who might read this would expect the same behaviour, also. Thankfully, I found the XCode4_beginning_of_line plugin on github that corrects this shocking oversight on Apple’s part.


  5. Just tonight I tried to debug some code (for the first time), and after remapping the “step over” key from F6 to F10 (I’m so used to the Visual Studio key that I cannot change this old habit!), I discovered that stepping over code doesn’t always mean step over in XCode. It quite often means “step into a massive page of assembly code”, which, I’m sure you might agree, isn’t particularly useful, especially if you’re like me and don’t know squat about assembly! Here’s a picture showing what I’m talking about, and no, I’m not using a release configuration. There’s also a Show Disassembly When Debugging option which I do not have ticked, either. Encountering this major annoyance is what prompted me to write this blog posting, so perhaps I’ll find the answer tomorrow, but for now, I’ve tried the obvious things and got nowhere. If this is Apple’s idea of “stepping over” whilst debugging, then perhaps I should just go back to Linux. I wonder if Ubuntu is usable again? Have they junked Unity and is GNOME 3 not stupid anymore?


  6. What made me give up and walk away from the computer yesterday was discovering that concatenating strings in Objective-C isn’t as simple as doing this:
  7. NSString *string = @”hello ” + @”world”;

    The correct way is this:

    NSString *string = [@”hello” stringByAppendingString:@”world”];

    Which brings me to another thing, Objective-C’s “message expressions”. I sure do miss being able to type object.method()! Having to type an at-symbol before every Objective-C string is very annoying, but without it, I’m using C strings, which Objective-C doesn’t like. I’m sure Apple could do something here to deprecate this unfortunate requirement.


  8. Given that XCode has really rubbed me the wrong way these past couple of days, I fell like being petty now :-) In .NET if you want to add a .ToMyString() method to the String class for use on any string, you add what’s called an extension method. Sounds logical, you’re adding a method to a system class, effectively “extending” the functionality of .NET itself. Now in Objective-C, an extension method is called a “category“. Beats me why they chose this name because it’s utterly illogical. Category of what? Anyway, “class extension” might be a logical name, but apparently such beasts were added in Objective-C 2.0 and are simply a way to allow a class to have private methods as far as I can tell right now (strange that a language would have no “private” method support until only recently). Objective-C is basically plain old C with Smalltalk-style object messaging syntax. Since then it has had various things done to it, such as Automatic Reference Counting and other afterthoughts. It’s now at a point where I seriously think Apple could do well to invest in a complete overhaul of the language and give it the ability to use another syntax scheme, much like .NET has c# and VB. I know I’m just dreaming, and that Apple would probably only make any such syntax bizarre in their own special way, so I suppose I’m just going to have to learn to live with Objective-C as it is, and embrace the joys that self-whipping can offer.


I suppose there’s always Xamarin.Mac, but I so wanted to really give Objective-C and XCode a try, but Apple are not making it easy for anybody with exposure to what I regard as “normal” development experiences, such as Java, C#, Perl, PHP, JavaScript, etc, and “normal” IDEs. I knew very well that Apple had their own special way of doing just about everything, and so far, since switching to Mac in December 2012, I’ve managed to cope well enough. It’s a very reliable platform, but it seems that if you want to do more than be just a passive consumer and internet surfer, you’re in for a bumpy ride. If I had only ever known the Apple way of doing everything, I’m sure I’d be right as rain, but having come from a different background, the transition for a developer is extremely unpleasant indeed.

They say that moving house and changing jobs are two of life’s most stressful events. I suppose switching from PC to Mac is another one, especially if you’re a developer! So far I’m determined not to be beaten, but I seriously needed to get all this off my chest. Only by venting will I be able to get past it and force myself into another whipping session tomorrow. Wish me luck!

Read More

Bulk renaming files in Linux

For some time it’s been annoying me that the various GUI file renaming options in Linux weren’t quite good enough. They either require manual previewing/actioning each and every directory or those that do recursive processing were just very limited.

So, after finding this offering to get me started, enter the following shell script which I’ve put together to replace the three most annoying characters that Linux allows in file names (and which the various MP3 ripping programs also permit and don’t clean up):


# Replace double quotes with single quotes
find . -name '*"*' -depth -exec rename -v "s/\"/\'/g" {} +

# Strip question marks entirely
find . -name '*\?*' -depth -exec rename -v "s/\?//g" {} +

# Replace colons with periods
find . -name '*:*' -depth -exec rename -v "s/\:/\./g" {} +

Save the above to a file and set it to executable (chmod 755 and Bob’s your uncle. I still have quite a lot of tidying and tagging ahead of me after going on a CD-buying binge for the past 12 months, thanks to a stellar Aussie Dollar exchange rate, but at least I can now copy various MP3 rips to a FAT32 USB key and take them to work without Windows Explorer bitching at me.

Meh. The code isn’t showing entirely in the correct font/colour but I’m sure you’ll cope :-)

Read More

Desert Colour Scheme for NetBeans

Eyeball a white screen whilst programming for too long and your eyes are going to hurt, so a sympathetic colour scheme is essential. My favourite scheme, or at least the one I became used to when I used gedit a fair bit, is called Desert (no longer available, so here’s my copy), which is based on the Desert scheme for vim. Lately I’ve been using Geany to take advantage of a few more features, so here are of the relevant files from my “~/.config/geany/filedefs” directory which I modified to implement the same colours.

However, this Christmas I intend to read Programming Clojure, a book I bought just over a year ago! And since I haven’t been able to cope with emacs or vim, I was forced to once and for all put in the time to implement the Desert colour scheme in NetBeans. The process was quite laborious, so hopefully this will be useful to those who find the default offerings a little meagre.

Here’s a sample of the colour scheme, showing defpackage.clj from the clojure examples in the book. I have also configured these same colours for other file formats I use often, such as PHP, HTML, JS, CSS, SQL, and knocked up the others as best I could in the time available. NetBeans sure doesn’t make this easy, but you gets what you pays for :-)

(picture: preview showing desert colour scheme

Download: Desert Colour Scheme for NetBeans 59.3 KB (created with 6.9.1)

To install, open NetBeans, go to Tools > Options, then click on Fonts & Colors, then click the Import button at the bottom and browse to the file downloaded above. Enjoy!

Read More

Two years using Linux and I’m in computing heaven

This morning I wanted to scan an image, so I fired up Simple Scan in Ubuntu and clicked the scan button (by the way, using my cheap CanoScan LiDE 20 for which there was no 64-bit Windows 7 support for quite some time – now supported with a 10 MB driver/software download – but which Ubuntu supports out-of-the-box with no effort on my part). As soon as I see the picture on screen I decide to see if I can just stop it there and save what I want. Lo and behold, it doesn’t complain, I crop the image and click save, and it just saves without having to scan the image again like most dumb-ass commercial scanning packages. Very impressed.

I then decide that the image is a little too big, and not wanting to fire up The GIMP like I have been doing until now, I decide to search for a better way. A short Google search later and I find the nautilus-image-converter add-on to Ubuntu’s file manager. A mere 30 KB download using the Synaptic Package Manager (Add/Remove Programs on steroids for you Windows slaves) and a re-login later and I’m resizing images with ease.

If you search for “free image resizer windows 7” you get quite a lot and the only link I could safely say is free of viruses and spyware is Google Picasa, but since it appears in the Ads section, anybody with half a brain should be wary these days (except Google in this case). Search for any Windows software and you’re more likely to get spyware than not. Being a Linux user I don’t have that problem because my software only comes from a trusted source, and not the likes of or

I started using Linux seriously exactly two years ago when I happily took the buggy Windows Vista off my media centre PC and installed Mythbuntu 8.10. At the time I had to tinker a little to get my remote control working and a few other things but since installing 10.10 last weekend, I found it was an absolute cinch! By default it installed Samba and configured the same shares I did two years ago, there was an option for my remote control, and it looks more polished than before. The only thing I did as before was enable low noise amplification on my TV card. And since the transmitted digital TV guide in Australia is pretty decent now, I don’t even need to install Shepherd, which has served me very well. The new version of MythTV even comes with a Python script that automatically downloads matching artwork for my favourite TV recordings such as The Colbert Report and The Daily Show with Jon Stewart. My brother has been complaining about his unstable Windows 7 Media Center install (six months old). I might have to burn him an ISO of Mythbuntu. So, I wouldn’t even go back to Windows Media Center now if Microsoft paid me!

In the past I have said some very unpleasant things about PHP but now it’s all I use. It’s true that its function names are all over the place and everything is in the global namespace, but it’s just so darn convenient and widespread. Much like VB was looked down upon in the Windows world as a toy language, it didn’t change the fact that it made people’s lives easy and therefore became very popular. As far as languages go I’d really like to find the time to read the dead-tree edition of Programming Clojure that I bought (under the influence of the proselytisation of a better programmer than myself), but at the end of the day it’s all about results, and with PHP I’m more productive. Now I’m mixing PHP on the server with Ext JS on the client thanks to another good book, Learning Ext JS. I can’t see me installing a Windows Server at home any time soon.

If an operating system requires me to install anti-virus software then I’m going somewhere else. Using a virus scanner gives you a false sense of security and doesn’t do much except drastically slow down your computer. One of the best articles I’ve ever read on why Windows sucks big time is The Six Dumbest Ideas in Computer Security. Windows commits most of the sins mentioned and even with things like User Account Control I still wouldn’t use Windows 7 at home. You would have to pry Linux from my cold, dead, hands if anybody wanted me to stop using it :-)

Read More