yet another programmer yet another programmer - 6 months ago 23
Objective-C Question

What is this Objective-C/XCode annotation // [START_EXCLUDE]

Looking at sample code for GCM notifications on iOS found here: https://github.com/googlesamples/google-services/blob/master/ios/gcm/GcmExample/AppDelegate.m#L31

....
// [START register_for_remote_notifications]
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [START_EXCLUDE]
....
// [END_EXCLUDE]


What purpose do the // [START_EXCLUDE] // [END_EXCLUDE] serve. Is it part of a convention, part of Objective C or something for xCode?

Answer

Is it part of a convention, part of Objective C or something for xCode?

None of the above. Those are just comments as far as the compiler is concerned -- they aren't part of any standard Objective-C conventions, and they're not part of the language, directives that are understood by the compiler, or instructions understood by Xcode.

From some of the commit comments in the repo, the [START ...] and [END ...] seem to be directives to some sort of preprocessor, but that preprocessor isn't triggered when you build the project. Perhaps they're used by a tool that's external to the project, one that can be used to generate sample code with specific sets of options. If you look through the code, you'll find similar directives, such as:

// [START start_gcm_service]
...
// [END start_gcm_service]

and these all seem to surround chunks of code that might be excised from the code.