I'm using a singleton object in my app. The object needs to be re-set and basically recreated when the user chooses to do so. Right now I have the following code so that it works correctly.
if (obj == nil) {
[obj release];
obj = nil;
}
obj = [[self alloc] init:param];
Answer:
I found that obj already has it's memory allocated, so it does not need alloc anymore. To reuse the object, only the init method needs to be called... Instead of re initializing the object everytime, the following can be done:
+ (Obj*)sharedManager:(NSString*)param {
if (obj == nil) {
obj = [[self alloc] init];
}
[obj setAllParameters:param];
}
So basically, it will allocate the object only once. And it will always set the parameters. So simple! I feel like a true iphone idoit developer.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment