So if I get you right you want an instance of a given class that you can use across the whole of your application without losing the state of the class but this should only exist in the DEBUG
version of your code?
Ok we can do this using a Singleton Pattern mixed with the #ifdef DEBUG
to determine whether in debug mode or not.
DebugManager.h
// Our Debug Class that we have just made up.
// Singleton class
@interface DebugManager : NSObject
// Some properties that we want on the class
@property (nonatomic, strong) NSString *debugName;
@property (nonatomic, readonly) NSDate *instanceCreatedOn;
// a method for us to get the shared instance of our class
+ (id)sharedDebugManager;
@end
DebugManager.m
#import "DebugManager.h"
@implementation DebugManager
// Create a shared instance of our class unless one exists already
+ (id)sharedDebugManager
{
static DebugManager *sharedDebugManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedDebugManager = [[self alloc] init];
});
return sharedDebugManager;
}
- (id)init
{
if (self = [super init]) {
debugName = @"Debug Instance";
instanceCreatedOn = [NSDate new];
}
return self;
}
@end
Now that we have a Singleton class setup we can add the below line to our *-Prefix.pch
which will give us an instance of our DebugManager
class that we can use throughout our app.
#ifdef DEBUG
DebugManager *manager = [DebugManager sharedDebugManager];
#endif
Just remember that when you want to use your manager
instance you will need to wrap it in #ifdef DEBUG
because when running in production this will not see the instance of manager
anymore. So make sure you do:
#ifdef DEBUG
NSLog(@"The DebugManagers instance name is %@", [manager debugName]);
#endif
Don't forget to add your preprocessor macro in xcode under your Build Settings
follow this answer to find out how to do that
If you have any questions just ask below.