PDA

View Full Version : SYNTHESIZE_SINGLETON_FOR_CLASS : What is the use




mpramodjain
Jan 7, 2011, 03:28 AM
#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.



dejo
Jan 7, 2011, 09:24 AM
Can anyone please let me know , what is the exact requirement of the Macro, I mean what does it actually do at compile time..
#define does simple text-substitution at compile time.

mpramodjain
Jan 7, 2011, 10:48 AM
Thanks for the reply,

#define SYNTHESIZE_SINGLETON_FOR_CLASS(MySingleTonClassName)

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

dejo
Jan 7, 2011, 11:11 AM
To be clear what does the macro SYNTHESIZE_SINGLETON_FOR_CLASS(MySingleTonCassName) do exactly..

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 (http://www.cprogramming.com/reference/preprocessor/define.html) for the two uses of #define.

chown33
Jan 7, 2011, 11:13 AM
Thanks for the reply,

#

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

Referring to this article:
http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

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.

mpramodjain
Jan 9, 2011, 10:41 PM
Referring to this article:
http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html


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.