tags:

views:

134

answers:

3

Hi I want to implement singleten design pattern in iphone code

I have one array. I want it to retain its value between function calls of from single class function.

How Can I use singleten design pattern to do above task? Thanks.

+1  A: 

Matt Gallagher has a pretty good writeup, with a very simple to use preprocessor macro to set create a singleton for class:

http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

duncanwilcox
+2  A: 

Already discussed here

Vladimir
Thanks Vladimir. Its rally very Helpful.
Nic
Note that I just edited that to include a number of methods that are a good idea to also have in a singleton.
Kendall Helmstetter Gelner
+2  A: 

better you can initialize it in appdelegate of your project. then you can access this array anywhere in your project.

define UIAppDelegate ((yourAppDelegate *)[UIApplication sharedApplication].delegate)

include this in your your appDelegate, then you can access your array any where you want.

UIAppDelegate.yourArray

Rahul
Thanks. Its good.
Nic