Better Xcode warnings through .xcconfig files

Peter Hosey posted a list of warnings he turns on. Here’s the warnings I turn on. It’s mostly the same list.

Rather than set these per project, I have a .xcconfig file I add to my project. I then base each build configuration off this file. Changing the .xcconfig file changes all projects based on it (though with the current Xcode, it’s sometimes necessary to reload the project to get the settings to take).

//
//  MoreWarnings.xcconfig
//
//  Created by Steven Fisher:
//      http://tewha.net/2010/11/xcode-warnings/
//  See also:
//      http://boredzo.org/blog/archives/2009-11-07/warnings
//

GCC_WARN_CHECK_SWITCH_STATEMENTS = YES GCC_WARN_SHADOW = YES GCC_WARN_64_TO_32_BIT_CONVERSION = YES GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES GCC_WARN_ABOUT_RETURN_TYPE = YES GCC_WARN_MISSING_PARENTHESES = YES GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES GCC_WARN_ABOUT_MISSING_NEWLINE = YES GCC_WARN_SIGN_COMPARE = YES GCC_WARN_UNDECLARED_SELECTOR = YES GCC_WARN_UNUSED_FUNCTION = YES GCC_WARN_UNUSED_LABEL = YES GCC_WARN_UNUSED_VALUE = YES GCC_WARN_UNUSED_VARIABLE = YES GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES GCC_TREAT_WARNINGS_AS_ERRORS = YES RUN_CLANG_STATIC_ANALYZER = YES

Peter wrote a great explanation of why you’d want most of these warnings, which I’m not going to attempt. I’ve added some C++ warnings, too. They don’t do anything with clang 1.6, but might be useful in the future.

A few notes:

  • Like Peter, I don’t turn on GCC_WARN_UNUSED_PARAMETER. Although you can add __unused to each parameter to disable the warning, doing so breaks Xcode’s code formatting. I use code formatting constantly, so anything that breaks it isn’t acceptable.
  • The warnings that were the most painful to turn on were GCC_WARN_64_TO_32_BIT_CONVERSION and GCC_WARN_SIGN_COMPARE. If you use int and NSInteger interchangeably, you’re going to have a tough time with these. (I don’t, but some of the internal libraries I use do.) These are also some of the more dangerous warnings to fix; if you’ve got automated tests, you should run them after every few corrections.
  • RUN_CLANG_STATIC_ANALYZER will roughly double (or more) the time your project takes to compile. I consider this a good trade: I rarely trigger a static analyzer warning now, but when I do I want to fix it.
  • Also note the GCC_TREAT_WARNINGS_AS_ERRORS. If you are applying these to an existing project, you may start with hundreds of warnings. You’ll probably want to start with this set to NO and change it to YES after you’ve fixed the warnings.
  • Remember, too, that this changes the defaults for settings. You can still specify different settings in the build configuration! If the static analyzer is taking too long to run in one project, just turn it off in that one project but leave the .xcconfig file alone!
Posted in Technology | Tagged , , , , | Comments Off

Changing UINavigationBar’s title text color

You can’t, directly, but you can substitute your own view.

For example, start with Apple’s NavBar sample. Drop this code into initWithNibName:bundle: in PageThreeViewController.m:

?

- (id)initWithNibName:(NSString *)nibNameOrNil
               bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // this will appear as the title in the navigation bar
        CGRect frame = CGRectMake(0, 0, 400, 44);
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:20.0];
        label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor yellowColor];
        self.navigationItem.titleView = label;
        label.text = NSLocalizedString(@"PageThreeTitle", @"");
        [label release];
    }

    return self;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
- (id)initWithNibName:(NSString *)nibNameOrNil
               bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // this will appear as the title in the navigation bar
        CGRect frame = CGRectMake(0, 0, 400, 44);
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:20.0];
        label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor yellowColor];
        self.navigationItem.titleView = label;
        label.text = NSLocalizedString(@"PageThreeTitle", @"");
        [label release];
    }

    return self;
}
Posted in Technology | Tagged , , | Comments Off

Greater transparency and flexibility for App Store developers

From Jim Dalrymple over at The Loop: Apple promises greater transparency for App Store developers:

A new statement from Apple would seem to indicate a more conciliatory and open approach to its relationship with developers of software for iOS devices. It’s great news in particular for developers who rely on cross-platform software toolkits, which seemingly ran afoul of Apple’s SDK license earlier this year.

Jim’s got (as usual) a smart take on this. But great news for cross-platform software toolkit users? I wouldn’t go that far. It’s really going to depend on the toolkit, and its usage. I think there’s more than enough ammunition in the App Store guidelines list for Apple to continue to reject (for example) any misbehaved Flash apps. They just won’t say it was for being built with Flash anymore. The same with any other toolkit.

Which is smart. If someone manages to meet all of Apple’s criteria with a Flash-built app despite the runtime, why shouldn’t it be published? But keep in mind: That’s probably not possible, except possibly for full screen games. And even they are going to be walking all over battery life.

Edit: The above looked like I was equating cross-platform software toolkits with Flash. Unintentional. Fixed.

Posted in Technology | Tagged , , , | Comments Off

Apple’s developer search improved

About a year ago, I complained about how bad Apple’s search engine was for developer documentation.

I’m not going to claim it’s perfect now, but the new developer website Apple pushed today improves it. The useless summaries (that always turned out to be the same boilerplate for every result) are gone, as are the duplicates in different formats. And the results are more relevant too.

Check it out here.

Posted in Technology | Tagged , , , | Comments Off

New iPods and free ponies for all

Macworld covers an Apple special event on September 1st. But their predictions hedge bets, offering a “good chance” of something more substantial than just new iPods.

Well, I’m not famous or Internet famous, so I can go out on a limb and give you a guarantee of what you’ll see. And nobody will care if I’m wrong. So here’s my prediction. Are you ready?

  • New iPods.
  • An updated iTunes.
  • That’s it.

You will not see an updated Apple TV. You will not see an iPad nano. You will not see The Beatles. You will not see cloud based syncing, unless it’s the only way to sync the new iPod. You will see changes to the iPod, the iPod, the iPod, and things directly connected to the iPod. Apple will stay on message. Given that the invite is in the shape of a guitar, the message is music.

Update: Well, I was wrong about the Apple TV, but I was right about cloud sync and the iPad nano.

Posted in Technology | Tagged , , , , , | Comments Off

Oliver Drobnik (Dr. Touch): Understanding iOS 4 Backgrounding and Delegate Messaging. State diagram for iPhone applications with respect to multitasking. The only thing I see missing is some times when your app will be killed, but you can’t handle those anyway.

Posted on by Steven Fisher | Comments Off

Cocoa With Love (Matt Gallagher): Assign, retain, copy pitfalls in Objective-C.

Posted on by Steven Fisher | Comments Off

Martin Pilkington (Code Collector Pro) on Objective-C 2.2 features. He covers the code reduction features of the new runtime. These are coming to “modern” Apple runtimes, meaning 64-bit Mac and iPhone.

Posted on by Steven Fisher | Comments Off

Matt Gammell of  Instinctive Code on a developer’s perception of their software’s complexity.

Posted on by Steven Fisher | Comments Off

Safari 5 extensions

Safari 5 introduces extensions in a simple way. I’ve already found more useful extensions than I found for Firefox:

  • Tynt-Blocker: Stops copy-paste tracking shenanigans.
  • Autocomplete: Stops banks, etc from disabling autocomplete.
  • No More iTunes: Prevents iTunes from being launched automatically when you visit an iTunes preview page.
  • GReader Checker: Add a button to the toolbar for Google Reader. Shows the number of unread articles.

If you haven’t yet, here’s how to enable extensions. I found most of these through Safari Extensions.

Posted in Technology | Tagged , , , , , | Comments Off