I am developing an iOS application. My used design pattern Singleton and Delegation patterns. I did nil a delegate object in dealloc method. If user re opened this screen and set to delegate object self. But I see delegate object always nil. How can I re assign to self to delegate object
Asked
Active
Viewed 367 times
2
-
3It's impossible to diagnose this from a description. Please post some code. – Sergey Kalinichenko Feb 05 '14 at 16:18
-
Where you are reassigning your delegate to self? – Naga Mallesh Maddali Feb 05 '14 at 16:51
-
Actually my problem delegate object do not re assign? I want to re assign to delegate object – hiwordls Feb 06 '14 at 08:36
3 Answers
2
Since your question is not detailed,
I would like to give you suggestion to double-check your singleton code first and
check whether of not your delegate is properly set along with your logic in the right way always.
I know this is too broad and general answer, However, it cannot be helped.
For reference, This Below code is Basic structure of Objective-C singleton under ARC.(for swift version, check the above answers.)
YourSingleton.h
@interface YourSingleton : NSObject
+ (YourSingleton*)sharedInstance;
@end
YourSingleton.m
#import "YourSingleton.h"
@implementation YourSingleton
#pragma mark - singleton method
+ (YourSingleton*)sharedInstance
{
static dispatch_once_t predicate = 0;
__strong static id sharedObject = nil;
dispatch_once(&predicate, ^{
sharedObject = [[self alloc] init];
});
return sharedObject;
}
@end

boraseoksoon
- 2,164
- 1
- 20
- 25
0
Use this in your singleton Class method
//Strict impelmentation of singleton with ARC.
//Object is created only once in the System.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if(myObject==nil){
myObject= [[myClass alloc]init];
}
});
return sharedEffcoreObject;

Prince Agrawal
- 3,619
- 3
- 26
- 41