1. Welcome to the new MacRumors forums. See our announcement and read our FAQ


Discussion in 'iPhone/iPad Programming' started by mpramodjain, Jan 7, 2011.

  1. macrumors regular

    #define SYNTHESIZE_SINGLETON_FOR_CLASS(MySingleTonClassName)

    static GameController *sharedGameController = nil; <===== (9)/QUOTE]

    Can anyone please let me know , what is the exact requirement of the Macro, I mean what does it actually do at compile time..

    Does it take care of having only one allocation of object over all the application code.

    Thank you.
  2. Moderator


    Staff Member

    #define does simple text-substitution at compile time.
  3. macrumors regular

    Thanks for the reply,

    To be clear what does the macro SYNTHESIZE_SINGLETON_FOR_CLASS(MySingleTonCassName) do exactly..
  4. Moderator


    Staff Member

    Can we see the entire #define? Looks like the formatting of it got a little messed up in your OP.

    And I was somewhat mistaken in my earlier post. See here for the two uses of #define.
  5. macrumors 603

    Referring to this article:

    SYNTHESIZE_SINGLETON_FOR_CLASS is a multi-line macro. It expands to the series of \-delimited lines of code that you see in SynthesizeSingleton.h. Like any macro, it also replaces occurrences of its parameters (classname in the given header), with whatever you've entered between the parentheses.

    If you don't know about \-delimited continuation lines, or don't understand macros in general, you should refer to a C reference book. Those things are plain standard C.

    If you're asking "please explain all the code", then I think you can read the article and the code well enough to work that out yourself. If not, then you need to review the fundamentals.

    If you have a specific question about a specific line of code in the expanded macro, then paste that line into a post.

    Expecting someone to provide an exact line-by-line explanation of a 50-line macro is expecting too much, especially since there's an article that explains how to use it. The whole point of creating macros is that you don't have to understand what's inside them, all you have to do is use them correctly, and I think the article outlines the correct use.
  6. macrumors regular

    Hi Chown,

    Thanks for sharing the url.

    After going through the url content (and SynthesizeSingleton.h file), I found that already I had implemented in my code (methods such as shared##classname etc) without using macro.So as per my little knowledge, I do think there would be no use to define macro as I am having only one singleton class all over the application.

    Please suggest if am in wrong way.

    Thanks for the reply.

Share This Page