Cocos2d: how to share player data between scenes
===

**I got a PlayerData class deriving from CCNode and I would like to share it between the various scenes of the game as static singleton instance.** 

I have tried the following implementation:

    #import <Foundation/Foundation.h>
    #import "cocos2d.h"
    @interface PlayerData : CCNode {
    
    }
    
    @property (readwrite, nonatomic) int data;  
    +(id) playerData;
    +(PlayerData*) sharedPlayerData;

    #import "PlayerData.h"
    @implementation PlayerData
    @synthesize data;
    static PlayerData* instanceOfPlayerData;
    
    +(id) playerData 
    {
        if(instanceOfPlayerData==nil){
            return  [[self alloc] init];
        }else {
            return [self sharedPlayerData];
        }
    }
    
    +(PlayerData*) sharedPlayerData{
       	NSAssert(instanceOfPlayerData != nil, @"PlayerData instance not yet initialized!");
        return instanceOfPlayerData;
    }
    
    
    -(id) init 
    {
    	if ((self = [super init]))
    	{
            instanceOfPlayerData=self;
            data=0;
            }
        return self;
    }
    @end

**Where is the right place to allocate this?** I thought about adding and accessing it to the AppDelegate class but I cannot quiet understand how.

I see that from the sharedDirector I can access to a delagate value but I don't think is the right one unless I have to cast it to my AppDelegate class. Any suggestion?

    [[CCDirector sharedDirector] delegate];


And this is my AppDelegate class as from template:

    #import <UIKit/UIKit.h>
    #import "cocos2d.h"
    
    @interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate>
    {
    	UIWindow *window_;
    	UINavigationController *navController_;
        
    	CCDirectorIOS	*__unsafe_unretained director_;							// weak ref
    }
    
    @property (nonatomic) UIWindow *window;
    @property (readonly) UINavigationController *navController;
    @property (unsafe_unretained, readonly) CCDirectorIOS *director;
    
    @end

**PS: I am using Cocos2d v2.x with ARC enabled**