'singleton'에 해당되는 글 1건

  1. 2010.06.21 Singleton + NSMutableArray
아이폰어플개발정보2010. 6. 21. 22:50
Singleton + NSMutableArray

[test.h]

@interface SingletonShopinfo : NSObject
{
 NSMutableArray *pmaShopinfo;
}

@property (nonatomic, retain) NSMutableArray* pmaShopinfo;

+ (SingletonShopinfo*) sharedShopinfoInstance;

@end

[test.mm]

#include "test.h"

@implementation SingletonShopinfo
@synthesize pmaShopinfo;

+ (SingletonShopinfo*) sharedShopinfoInstance
{
 static SingletonShopinfo *sharedShopinfoInstance;
 
 @synchronized(self)
 {
  if(sharedShopinfoInstance == nil)
  {
   sharedShopinfoInstance = [[SingletonShopinfo alloc] init];
  }
 }
 return sharedShopinfoInstance;
}

- (void) dealloc
{
 [super dealloc];
}

- init
{
    self = [super init];
    if (self) {
//        sessions = [[NSMutableArray alloc] init];
        pmaShopinfo = [[NSMutableArray allocWithZone:[self zone]] init];
    }
    return self;
}

[사용할곳]

#import "test.h"

- (void)viewDidLoad
{

[super viewDidLoad];

SingletonShopinfo *sharedShoinfo = [SingletonShopinfo sharedShopinfoInstance];

NSLog(@"Log %@" ,[NSString stringWithFormat:@"%d ", [[sharedShoinfo pmaShopinfo] count]] );

}

 


출처 : http://blog.naver.com/PostView.nhn?blogId=cbdman&logNo=130087817705
Posted by 오늘마감

댓글을 달아 주세요