Thursday, August 26, 2010

How to Remove Unused Parameter Warning

No Warnings Policy requires sometimes forcing a compiler warning to be ignored. One such case is when you are given a function you absolutely must use, but don't need the parameters:
- (void)applicationDidFinishLaunching:(UIApplication *)application
#pragma unused(application)
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
There are several ways to ignore warnings, I found #pragma to be a clean solution.

Wednesday, August 25, 2010

grep Regular Expressions and Internationalization

Wanted to find all meaningful text strings in an iPhone project, preparing for a proper internationalization:
grep -r '@"' * |grep -v -E 'NSAssert|NSLog|@""'
Forgotten this so many times, it's better to write it down: how to search for several patterns at the same time using grep on Mac OS X command line (bash shell). Could use also command line parameter -P (Perl Regular Expression) in this case, but -E (Extended Regular Expression) is more generic. why wasn't internationalization done in the first place, when things were still simple? Because in certain kind of experimental projects you need to get results fast and early to decide whether it's worth continuing at all. If available time is used for "doing things right", there won't be any (good enough) results and The Project Will Be Terminated.

Just a question when do you want to invest your time: early or later. Have to pay the price anyway. Usually the longer you wait, the higher the price will be. On the other hand at that time you might have afford it.

Multiple Info.plist files and UIApplicationExitsOnSuspend

I have three Info.plist files: one for release (Info.plist), second for release testing (Info_release.plist) and third for testing (Info_test.plist).

In other words, I generate three separate applications from same sources so that all can be installed in a device at the same time. Therefore the content of plist files are identical, except CFBundleIconFile and CFBundleIdentifier.

When looking at Info.plist in XCode I can see "Application does not run in backgr" with a checkbox, while the two other plist files show UIApplicationExitsOnSuspend. Open all three files as source code or text and they contain exactly the same code:
Weird... still everything seems to work ok. Just a note. Btw official documentation is available here.

Tuesday, August 24, 2010

How to Show Text Left and Right in UIWebView

When you need to show text on same line at left and right in UIWebView, this is one way:
NSString *myHtml = [NSString stringWithFormat:
    "<span style='float:left'>%@</span>"
    "<span style='float:right'>%@</span>"
    @"I'm left", @"I'm right"];
[self.cellWebView loadHTMLString:myHtml baseURL:nil];
Can't use div, since it seems to force a linebreak by default.

Monday, August 23, 2010

How to Get Share Buttons into Blogger

Blogger supports Share Buttons - officially.

Unofficially you might have to do some manual tweaking to make it actually work: Solution: Blogger Share Buttons not showing up? and reverse style.