Uncaught exceptions in Objective-C

When debugging Objective-C applications, it’s really useful to be able to see where uncaught exceptions are generated. Let’s see how this can be achieved using Xcode (current version 4.3.2) or JetBrains AppCode (current version 1.5.2).

Using Xcode

First show the Breakpoint Navigator, either from the View / Navigators menu, or using the keyboard shortcut ⌘6. By default you won’t see any breakpoints just yet. From the lower-left corner, press the + symbol to add a new breakpoint, and select “Add Exception Breakpoint” from the menu.

That will take you to the next step, where you just need to press the Done button:

Now, whenever an uncaught exception is generated while the current project is being debugged, Xcode will stop the execution and take you to the line where the exception has taken place. If you’d like this behavior in all your projects without having to go through the above steps each time, just right click on the “All Exceptions” breakpoint you previously added and choose Move Breakpoint To User. That’s it.

Using AppCode

If you’re using the cool AppCode IDE for developing Obj-C apps, there is a way to achieve the same behavior in that as well. Open the project in AppCode and navigate to the Run / View Breakpoints menu, or use the shortcut ⇧⌘F8. Then choose the tab called Exception Breakpoints. By default that section is empty.

Now simply press the Add button on the right hand side of the dialog to get the following result:

That will give you a breakpoint which will suspend the execution of your application whenever an exception is thrown. You can further customize the behavior in such cases by logging the corresponding message to the console, for example.

Happy debugging everyone. :)

Zonga

I’m happy to let you all know that the new media kid is on the block and it is called:

It is a great new way to enjoy tons of music, everywhere, all the time. Your entire music collection is synced across the web, your computer and mobile devices (iPhone and Android).

For now, the project is in “private beta”. That means it’s not yet open to everyone. On the Zonga.ro website you’ll find a bunch of ways to follow the project as it matures. There you can also register to be notified when the project becomes available to the public.

My involvement in all this? Well, I got on this plane in midair, as it was taking off. Otherwise put, I inherited the mobile projects from the great team of mobile developers from iQuest, and have been given the challenge to see it through its first release and beyond.

I already know this will be the next big startup, since I’ve seen how many talented people have put a lot of energy and passion into it, myself included.

Stay tuned for more…

Galaxy Nexus Battery Life

Recently I’ve got myself the new Samsung Galaxy Nexus (I9250). Having such a big screen, I thought this phone is not usable for day-to-day tasks, but only for development. So far, all the other Android devices have really let me down when it came to their battery life. The only smartphone up for a challenge so far was the iPhone 4.

But I am impressed. Under heavy usage, it lasts through the day. Even more surprisingly, used moderately, it even lasted two full days. Check out the pics below:

Anyway, I’m still looking forward to the future. Maybe in 5 years we’ll all have smartphones that recharge using sunlight. It would be awesome to not have to recharge your device… ever.

Lines of Code

I know it’s been a while since my last post, but I’ve been quite busy lately writing some code in my free time (you’ll find out soon enough what it is and I really hope you’ll like it). After everything has passed through the QA and acceptance testing, I stopped an looked at the code and wondered… How much time did it really take to write it? How much code did I actually write? So that’s when I remembered about the metric called source lines of code. I know it’s not really an objective metric, but it still measures the productivity from a certain point of view.

Since I wasn’t going to start opening every source file by hand and keep adding the number of lines myself, I thought that for sure there are some smart people out there who must have written a script to do that. That’s when I found this neat project: CLOC. It is a pretty powerful Perl script with lots and lots of options and room for customization. But I was simply interested in some raw statistics, like the number files, number of empty lines, number of lines of documentation, and of course lines of code. That’s a really simple task to perform using this script. Simply run the following command:

perl cloc.pl src_dir

or simply

cloc.pl src_dir

and you’ll get the results you’re looking for.

The cloc.pl is the script that you can download from the project’s web page and src_dir is the actual folder on the disk where you keep all your source files. In order to use the second version of the command you must first set the right permissions for the script. For more details on how to use it see the project’s page.

Outlook 2011 & Spotlight

As you’ve probably read in my last post, I recently switched to a Mac for my everyday (and night) work, as a necessity. Also as a necessity, I’ve started using the new Office 2011 for Mac, which includes a pretty decent version of Outlook. Coming from Windows, I didn’t have any problems adjusting to this email client, as Mac old timers had when they abandoned Entourage.

I personally don’t like having my entire home folder encrypted using FileVault, but on the other hand I like protecting my data. The easiest way to achieve this is to create an encrypted volume, which you also easily backup by just copying it to an external hard drive. In order to create the encrypted volume, you have at least two ways: using the Mac OS X built-in Disk Utility (check here for instructions), or by using a third party tool like TrueCrypt. I’m not going to debate which is the best options, since they each have their pros and cons. The important point here is that you’ll have all your important data into one encrypted file container, which you’ll mount as a volume when you want to access it. Now, when you do that, you’ll find it under the folder /Volumes/Data, in case you’ve named your volume Data.

Since Microsoft has its own ways, of course it will not let you configure where to save your emails or any other Office related settings. By default it will store everything under your home documents folder: ~/Documents/Microsoft User Data. That will simply not work for me, since I want my emails encrypted and easy to backup. To achieve this, one could simply move the user data folder on the encrypted volume. Here’s how you do that:

  • Close Outlook and any other apps in the Office suite.
  • Move the ~/Documents/Microsoft User Data to /Volumes/Data/Microsoft User Data.
  • Create an alias for the /Volumes/Data/Microsoft User Data folder and move it back to the Documents folder. Make sure it is called exactly Microsoft User Data.

Now, every time you’ll open Outlook it will look for the user identity, preferences, email accounts, etc. in your encrypted volume. This is quite convenient.

BUT, there’s a catch. Office 2011 uses the built-in indexing and searching mechanism called Spotlight. Moving the user data folder to another volume as we just did might break your searching features in Outlook, including smart folders, contact name checks, etc. Luckily there’s a fix for that. First, you need to make sure your encrypted volume is not in the Spotlight’s privacy list. To check for that open a Finder window and go to Applications/System Preferences/Spotlight/Privacy. If the volume is in that list you’ll have to remove it.

This might not be it. Next thing you need to do is to open a Terminal and type:

mdutil -s /Volumes/Data/

You might see that the output will say “Indexing disabled”. Don’t worry. Run this command in the Terminal:

sudo mdutil -i on /Volumes/Data/

This will execute the mdutil command as a super user, turning indexing on for the mentioned volume. In a few seconds the spotlight icon in the top-right corner of you screen will begin to animate, as the indexing has been started. Clicking on that icon will reveal a progress bar for the process. When Spotlight finishes, just restart Outlook and you’ll get all your emails searchable in an encrypted volume.

Anyway, don’t forget the golden rule: backup, backup, backup. ;)

Mac OS X & locked files

Until this week “I was a PC” for as long as I can remember, but now “I’m a Mac”. ;)

There are many things to get used to with the new OS (which is absolutely superb by the way). The data migration was rather easy. I just had to move my FAT32 encrypted partitions created with TrueCrypt from one machine to the other, and I was almost ready to go. I only had to install around 40 or so more apps and done. Right?

Well, not quite. As it seems, not everything is that straightforward. One problem I ran into while starting to use my Mac on a daily basis was the issue of “locked files”. When moving files from Windows to Mac, some of the files became locked. Don’t ask me how. If you know the answer, write me a comment.

When trying to update from SVN, I got a bunch of errors. Having some basic experience with Linux, I thought of ownership and permissions first. But I was the owner and had full permissions, so that wasn’t my problem.

Locked files actually are a level of security beyond permissions. In my case it was the uchg (user immutable) flag. You can see that in the file information panel, or in a Terminal if you run the command: ls -alO. What it does is actually locks the files and doesn’t allow you to move or delete them.

I needed a quick fix on my entire project directory, so I opened the Terminal, changed the working directory to where my project was and ran the command:

sudo chflags -R nouchg *

The sudo part was just for safety, to make sure I had enough privileges on the entire tree. The actual command was the chflags, with the -R parameter for recursiveness. To remove the uchg flag you actually have to negate it, thus the nouchg form, followed by the designated files, in my case, all of them.

I know there are probably lots of scripts and visual tools out there that can accomplish the same thing, but I really like to get down into a good old black and white, text only window every now and then.

I hope this helps some of you Mac users who are running into the same problem, and who are not system admins or power users (well at least not yet anyway). :)

Total Commander & custom compare tools

Those of you who are a bit more technical might use a “swiss tool” named Total Commander as part of your everyday routine.

Two of the features that I personally use a lot are called Compare By Content and Synchronize Dirs. The reason I use these features is to sometimes compare text files like configuration or source code files.

Although I absolutely enjoy working with Total Commander, I don’t like the built-in compare tool not one bit. That is why I’ve replaced it with another, third-party file compare tool. Now, there are quite a few options on the market, but the integration process is the same for all.

Considering of course you’ve already installed Total Commander and your compare tool of choice, open Total Commander and from the Configuration menu choose Change Settings Files Directly. This command will open two editors for the two configuration files wcx_ftp.ini (used for FTP connections) and wincmd.ini (the actual Total Commander settings file). The second one is where we need to make our changes.

At the top of the settings file there’s a [Configuration] entry. Right under it enter a new line and type:

CompareTool=<full_path_to_compare_tool_executable>

Of course you’ll have to replace the <> part with an actual path. Let me give you a few examples:

WinMerge:

CompareTool=C:\Program Files (x86)\WinMerge\WinMergeU.exe

DiffMerge:

CompareTool=C:\Program Files (x86)\SourceGear\DiffMerge\DiffMerge.exe

SmartSynchronize:

CompareTool=C:\Program Files (x86)\SmartSynchronize 3.2\bin\smartsynchronize.exe

After you’re done editing the settings file simply save and close it, then you can start comparing right away using the new tool, directly from Total Commander.

P.S.

WinMerge is an open source project, so the tool itself is free. It only runs on Windows and the latest version (2.12.4) has been released quite a while ago, in June 2009.

DiffMerge is a free tool developed by SourceGear. The latest version (3.3.0) is from April 2009. A big advantage over WinMerge could be the fact that it runs not only on Windows, but on Linux and Mac OS as well. That might be important for those who use several operating systems and would like to have the same utility programs on all OS instances.

SmartSynchronize is by far the best compare tool I’ve used so far. It will set you back 39 USD for a single user license, but I think it’s worth it. If you’re using any of the other tools developed by Syntevo, you’ll know what I mean. This tool is actively developed. The latest version (3.2.1) was released in October 2010. It is cross-platform as well.