diff --git a/SynthesizeSingleton_ForARC.h b/SynthesizeSingleton_ForARC.h new file mode 100644 index 0000000..e40a55f --- /dev/null +++ b/SynthesizeSingleton_ForARC.h @@ -0,0 +1,51 @@ +// +// SynthesizeSingleton.h +// CocoaWithLove +// +// Created by Matt Gallagher on 20/10/08. +// Copyright 2009 Matt Gallagher. All rights reserved. +// Edited by Mahyar Abutalebi and Maysam Shahsavari on 26/3/13. +// +// Permission is given to use this source code file without charge in any +// project, commercial or otherwise, entirely at your risk, with the condition +// that any redistribution (in part or whole) of source code must retain +// this copyright and permission notice. Attribution in compiled projects is +// appreciated but not required. +// + +#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \ + \ +static classname *shared##classname = nil; \ + \ ++ (classname *)shared##classname \ +{ \ + @synchronized(self) \ + { \ + if (shared##classname == nil) \ + { \ + shared##classname = [[self alloc] init]; \ + } \ + } \ + \ + return shared##classname; \ +} \ + \ ++ (id)allocWithZone:(NSZone *)zone \ +{ \ + @synchronized(self) \ + { \ + if (shared##classname == nil) \ + { \ + shared##classname = [super allocWithZone:zone]; \ + return shared##classname; \ + } \ + } \ + \ + return nil; \ +} \ + \ +- (id)copyWithZone:(NSZone *)zone \ +{ \ + return self; \ +} \ + \