
Question:
My Questing is
-(ABC*)createInstance { Static ABC *obj = [[alloc ABC] init]; if(obj == nil) { obj = [[alloc ABC] init]; } return obj }
can we write in objective c
[[ABC createInstance] release]
Solution:1
Yes, users could release your instance if you haven't overridden retain
/release
. Take a look at common singleton patterns for better approaches.
Notes:
- It is
[ClassName alloc]
, not[alloc ClassName]
- If you meant to make
createInstance
a class method use+ (ABC*)createInstance;
- It is
static
, notStatic
- You have to initialize
obj
tonil
- Use
self
instead ofABC
if subclassing is a concern:[self alloc]
- The common name for these methods is
sharedInstance
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon