Skip to content


Some more Xcode and iOS apps tips & tricks for beginners

I posted some tips and tricks in this previous post already, here are more as I discover them on my journey to getting used to Mac OS, Xcode and Objective-C (and some day Swift probably ^^)

How to type some of those characters that are totally necessary for programming
By this I mean things such as | (pipe / vertical bar), {} (braces / curly brackets) or [] (chevrons / angle brackets). That’s right, maybe you are luckier than I, but on the MacBook Pro I use for development, Apple thought it would be a good idea not to display those characters on the keyboard. Seriously WTF…
Anyway, here are the shortcuts, although note that I have a French “AZERTY” keyboard and it might sadly be different on yours :

  • the pipe | can be obtained using Shift + Alt + L (thank god for this old blog post where I found it)
  • the backslash \ can be obtained using Shift + Alt + / (slash) (thanks same blog post again)
  • the braces {} can be obtained using Alt + ( (same key as 5) and Alt + ) (same key as °) (found it myself by pressing about every combination I could think of… reminded me how I used to push every button in Windows 3.1 as a kid, hurray for modernity!)
  • the chevrons [] can be obtained using Shift + Alt + ( and Shift + Alt + ) (ditto)
  • the tilde ~ can be obtained using Alt + N (for some crazy reason, all the “solutions” I found call the “Alt” key the “Option” key, go figure…)

How to reduce indentation of a bock of code
In Windows, reducing indentation of a code block is easy because the tab key (which is used to increase indentation) can be used to produce a reverse tab (by pressing Shift + Tab), and this reverse tab can usually be used to reduce indentation. In Mac OS I still haven’t found how to produce that reverse tab, but code indentation can be reduced the following way:
– select your block of code
– right click it
– in the contextual menu, look for Structure -> Shift Left

How to disable a specific deprecation warning with pragma
I prefer to keep all warnings on so as to be proactive about trouble, because in most cases a warning is likely to eventually turn into a nasty error. But this is not the case with every warning. Notably, you can’t get rid of deprecation warning if you want to keep supporting old iOS versions, for instance if you do something like

if(newFunctionExists) {
    doModernCode
} else {
    doDeprecatedCode
}

This is annoying because it puts an end to the quest to no warning in the project. Luckily, there’s a clean solution to this: you can disable the deprecation warning (or actually any other warning if you choose so) just around the block or line of code of interest. The code for this looks like:

#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[here goes your deprecated code]
#pragma clang diagnostic pop

(you may need to replace clang with GCC if you use the GCC compiler instead of clang) Pretty neat, isn’t it? 🙂
If you want to read more about pragma, I found this nice post, which is where I found out it could be used to disable warnings – after that all I had to do was find the codename of the deprecation ones.

Even neater, you can also define a macro, like this:

#define SILENCE_DEPRECATION(expr)                              \
{                                                                   \
_Pragma("clang diagnostic push")                                    \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")   \
expr;                                                               \
_Pragma("clang diagnostic pop")                                     \
}

#define SILENCE_IOS7_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
#define SILENCE_IOS8_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
#define SILENCE_IOS9_DEPRECATION(expr) SILENCE_DEPRECATION(expr)

And then use it like:

SILENCE_IOS7_DEPRECATION([here goes your deprecated code])

This way you can easily keep track of what code to remove when you eventually decide to drop support for very old iOS versions.

How to remove analyzer warnings from the list of warnings
As I was desperately trying to produce an archive (like this except that it doesn’t freaking work) of my app in an attempt to maybe manage to send it to other people so that they can test it (can’t believe the hell this is on iOS while it’s so trivial on Android), I “accidentally” analyzed my project. It gave me a few interesting warnings but also quite many not so relevant ones. So now my almost warning-free project is flooded with 50+ extra warning from the analyzer from Hell. Gladly, they can be purged, to do so, simply go to Product -> Clean : this will remove analyzer messages (as well as all warnings too) from the issue navigator. Then next time you build the normal warnings will come back, but not the ones from the analyzer (until you choose to run the analyzer again, that is).

Posted in programming, Xcode.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA