Archive for the ‘Xcode’ Category

Localizing Localizable.strings woes

Wednesday, April 22nd, 2009

While localizing the Localizable.strings file of Be Tv I encountered a rather curious (mis)behaviour. I used the NSLocalizedString macro wherever I needed to get my localized text and used the genstring command to generate the Localizable.strings file. I made a dutch and french localization of this file and everything was working in the iPhone simulator. Nonetheless when deployed to my test device, the localization was not working. Localized nib files were though.

After fiddling with some Xcode settings, I gave up and resorted to Googling. Luckily I found this blog post, describing the exact same problem, giving an explanation why & providing a solution. Turns out the localized Localizable.strings file has the wrong encoding, UTF-8 instead of UTF-16. Change the encoding, do a clean rebuild and your localization is up & running.

To change the file’s encoding to UTF-16 from UTF-8, use ‘View’ –> ‘Text’ –> ‘File Encoding’ in XCode menu.

Credits go to Cagan Senturk.

Codesign failed with exit code 1

Thursday, March 26th, 2009

While building the final 1.0 product of Be Tv, I encountered the following error: “Command /usr/bin/codesign failed with exit code 1″. Searching the internet resulted in some posts with tips like check your certificates & provisioning profiles, check your app id for typos, .. After going through the whole distribution process, I was pretty sure that the aforementioned things were ok.

Eventually I found what caused the error, I had flagged the Info.plist file as Target, thinking it was necessary. (The checkbox at the far right) Unchecking it (which is the default state) solved it. When faced with the dreadful codesign error, here’s something extra you can check.

Break on exception in Xcode

Thursday, March 19th, 2009

One of the issues I encountered switching to Xcode, coming from Visual Studio, was related to exceptions. When an exception occurs in Visual Studio it breaks and shows the exact line that caused the exception, but by default Xcode has a different behaviour. When an exception occurs, some kind of general message is shown like “_objc_error”, “EXC_BAD_ACCESS” or “___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___” and no real indication is given where it happened. Stepping through your code to find the faulty line is time consuming and plain stupid.

Luckily you can configure Xcode to break on exception and here’s how. Let me first give you a little bit of background, when the compiler compiles your application in debug-mode, it adds extra information (called symbols) to the executable enabling Xcode to map the running statements to lines of code. This adds some overhead and is the reason (or one of the) why you shouldn’t deploy your application in debug-mode, but rather in release-mode (without the symbols).

That being said, let’s get to the interesting part, Xcode supports 2 kinds of breakpoints: (normal) breakpoints which are placed on a certain line and symbolic breakpoints. Chances are that you’ve worked with normal breakpoints hundreds of times, without knowing there was another type.

Symbolic breakpoints are breakpoints based on the method name instead of the line number of a file, the advantage of this is that the exact location of the method does not have to be known. Open the breakpoints window (Run – Show – Breakpoints) and add two symbolic breakpoints called “objc_exception_throw” and “[NSException raise]“. If you choose to make them in the Global group, they are available in all your projects while the Project group applies to the current project.

Symbolic Breakpoints

These two methods are used to throw an exception, the first one being the most recent style and the latter being the “old & traditional” style, for simplicity’s sake. If you run your code and a exception is raised your code will stop, just like it used to do without the extra symbolic breakpoints. But if you open the debugger (Run – Debugger) and browse the callstack, you should be able to locate the faulty line, which is displayed with a black font color, while the others are light gray. Click on it and your source code will be shown with the “exception throwing line” highlighted. While it’s not as fast/easy like Visual Studio which shows the baddie immediately, looking it up in the debugger works too, right?

Debugger

Important: while I’ve had great success with this, there have been times when the symbolic breakpoints did not work. The debugger would show the raw statements in the callstack when an exception occured, which is the behaviour without the symbolic breakpoints. I have been able to “fix” this by adding a normal breakpoint (I’ve put it in the method where the exception occured, but I think you can put the breakpoint anywhere) and running the code again, afterward the normal breakpoint could be deleted and the symbolic breakpoints would continue to work. I think it might have something to do with the normal breakpoint causing Xcode to load and/or process all the breakpoints or it’s just me doing something wrong. If anyone knows more about this issue, let me know in the comments.

Network activity indicator hidden in simulator

Tuesday, March 3rd, 2009

Yesterday I encountered this little nuisance, using Xcode 3.1.2 and firmware version 2.2.1. The following code snippet can be used to show and hide the network activity indicator in the status bar, yet when being run in the simulator it doesn’t work. When deployed to a device, the indicator is shown (and hidden afterwards).

Can’t really think of a valid reason why the indicator wouldn’t work on the simulator except that it is a bug, since I’ve made no changes to the code. I’ll have to see if it is a specific firmware 2.2.1 issue.

// Show network activity indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
 
// Hide network activity indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

Control reaches end of non-void function

Sunday, March 1st, 2009

Lately I’ve been getting a “control reaches end of non-void function” warning when compiling. Although it didn’t make any sense since I was not returning any value and the function had a return type of void, the code ran fine too. A few days later it hit me, I had made a typo in the return type.

- (void*)load {
}

Lesson of the day: a return type of (void*) does the job, but (void) does it better.

Breakpoints in Xcode stop firing

Wednesday, February 25th, 2009

Apple’s Xcode is a nice IDE and just like every program it has its occasional quirks. Here’s a tip: when all of a sudden your breakpoints stop firing, without any apparent reason, try this: Instead of following Googles advice and deselecting the “Load symbols lazily” option in the Preferences screen, (which will solve the breakpoints not hitting, I have to admit) perform a cleanup of your target. (Build – Clean All Targets) This will remove all intermediate files created during the build process and will force Xcode to process every file the next time you build, basicly a full rebuild. Xcode processes only the changed files during subsequent builds, but apparently this incremental strategy fails once in a while, with the aforementioned effect.

In the end both methods solve the problem, but I like to leave the default settings on, instead of changing them to fix some glitch in the system.

As posted on Smartasses.