I Am Finley

Xcode

Preprocessor Macros and User-Defined Settings in Xcode

0 Comments

As I have built more iOS apps over the last couple of years one of the biggest struggles I have had is the switch between development and release server APIs. More than a few times I have released an app pointing at the dev API. Not only is this an embarrassment, but it creates a logical nightmare in trying to redirect traffic from the dev environment to the live. Needless to say, there has to be a better way.

Over the weekend with a bit of research— which has me kicking myself for not doing it sooner— I found the best solution in Preprocessor Macros and User-Defined Settings. They are easy to set up and easy to use.

  1. Go to your Build Settings
  2. Go to the Editor menu, Add Build Setting, Add User-Defined Setting
  3. Give your setting a name, mine is called APIURL
  4. These settings have a Debug and Release value: set both
  5. Search in Build Settings for Preprocessor Macros
  6. Add APIURL=\@\"${APIURL}\" to both Debug and Release

You will now have a variable available anywhere in your code called APIURL. When compiling your app in Debug mode, you get the Debug value. When compiling your app for Release, you get the Release value. No more mistakes.

Permalink

IBInspectable / IBDesignable

0 Comments

Marked with @IBInspectable (or IBInspectable in Objective-C), they are easily editable in Interface Builder's inspector panel. Note that Xcode goes the extra mile here—property names are converted from camel- to title-case and related names are grouped together.

[...]

As if that weren't enough, IBDesignable custom views also debut in Xcode 6. When applied to a UIView or NSView subclass, the @IBDesignable designation lets Interface Builder know that it should render the view directly in the canvas. This allows seeing how your custom views will appear without building and running your app after each change.

IBInspectable / IBDesignable

These new methods are downright game changing, in my opinion, for Interface Builder. I have, like many developers, had a hot/cold relationship with Interface Builder. One of my biggest grumbles is custom views. Some projects don’t have a lot of custom views, so I’m down with IB. Others have a ton, so I’m not. Now with a limited amount of work, I can make my custom view configurable in Interface Builder. Might have to give this a try in my next app.

Permalink